繁体   English   中英

黄瓜步骤定义为“鉴于我已登录”

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

我有一个黄瓜步骤:鉴于我已登录

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

有人能指出我正确的方向,教程,博客等。

这是我怎么做的。

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

我这样做的原因是,我运行整个堆栈并按照普通用户的方式设置环境......

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

1. visit login page
2. fill_in login, username
3. press login button

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM