Cucumber step definition for “Given that I'm logged in”

后端 未结 2 508
不知归路
不知归路 2021-01-12 15:51

I\'ve got a cucumber step: Given that I\'m logged in

I don\'t understand how I should implement it as a step definition.

Could someone point me into right di

相关标签:
2条回答
  • 2021-01-12 16:05

    here is how I do it.

    Given /^I have one\s+user "([^\"]*)" with email "([^\"]*)" and password "([^\"]*)"$/ do |username,email, password|
      @user = User.new(:email => email,
                       :username=>username,
                       :password => password,
                       :password_confirmation => password)
       @user.save!
    end
    
    Given /^I am an authenticated user$/ do
      name = 'exmample'
      email = 'example@example.com'
      password = 'secret!'
    
      Given %{I have one user "#{name}" with email "#{email}" and password "#{password}"}
      And %{I go to the user login page}
      And %{I fill in "user_username" with "#{name}"}
      And %{I fill in "user_password" with "#{password}"}
      And %{I press "Sign in"}
    end
    

    The reason I do it this way, is that I run through the entire stack and set the environment up the way a normal user would...

    0 讨论(0)
  • 2021-01-12 16:16

    Hi You may divide this step into three smaller steps

    1. visit login page
    2. fill_in login, username
    3. press login button
    
    0 讨论(0)
提交回复
热议问题