Ruby on rails “黄瓜步骤”的定义;鉴于我';“我已登录”;

Ruby on rails “黄瓜步骤”的定义;鉴于我';“我已登录”;,ruby-on-rails,ruby,rspec,cucumber,Ruby On Rails,Ruby,Rspec,Cucumber,我有一个黄瓜步骤:考虑到我已登录 我不明白如何将其作为步骤定义来实现 有人能给我指出正确的方向、教程、博客等吗?您好,您可以将此步骤分为三个较小的步骤 1. visit login page 2. fill_in login, username 3. press login button 我是这样做的 Given /^I have one\s+user "([^\"]*)" with email "([^\"]*)" and password "([^\"]*)"$/ do |username

我有一个黄瓜步骤:考虑到我已登录

我不明白如何将其作为步骤定义来实现


有人能给我指出正确的方向、教程、博客等吗?

您好,您可以将此步骤分为三个较小的步骤

1. visit login page
2. fill_in login, username
3. press login button
我是这样做的

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

我这样做的原因是,我运行了整个堆栈,并按照普通用户需要知道您使用的身份验证系统的方式设置了环境…