且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

“鉴于我已登录"的黄瓜步骤定义

更新时间:2022-12-10 10:03:26

这是我的做法.

Given /^I have ones+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...