2

例如,当用户已经登录时,用户不应该看到登录页面。我应该如何在 cucumber 中实现此功能?

Scenario: Authorizzation
  Given I am logged in
  Then I should not be asked to authenticate


Given(/^I am logged in$/) do 
  @user = User.new
end

Then(/^I should not be asked to authenticate$/) do
  # what to write???
end

假设认证页面称为登录。

4

5 回答 5

1

就像是:

page.body.should_not include_text("Please enter your credentials")
于 2013-09-18T20:29:45.453 回答
1

I think you are fundamentally approaching it from the wrong direction. You might instead assert that I should see something that you expect like a link, text, or other. You can also follow a link one more level that you can assert you have proper access too.

It's hard to test something that isn't happening and you have no evidence, so test what you expect, not the world of things for which you can't test.

于 2013-11-15T14:43:57.880 回答
1

如果没有看到您现有的代码,很难假设。但它是沿着这些路线

Given...do  
  ...
  arg1.should  #=> should
  ...
end

Given...do
  ...    
  arg1.should_not #=> should not
  ...
end

更新

Then(/^I should not be asked to authenticate$/) do
  # what to write???
  unless @user.logged_in?  #=> assumes there is a method that checks it
    routines to login
  end
end

根据我的实践经验,我建议您掌握 Ruby 基础知识以享受黄瓜。此外,当场景说明应该发生什么时,它非常有用。

Scenario: Authentication
  Given user is not logged in
  Then he should be asked to authenticate  #=> (OR) Then he should be redirected to login page
于 2013-09-18T20:20:05.163 回答
0
Then /^(?:|I )should not be on (.+)$/ do |page_name|
  URI.parse(current_url).path.should_not == path_to(page_name)
end
于 2013-12-31T15:30:56.937 回答
0

在登录页面上,似乎应该出现“登录”或“登录”等按钮。因此,登录后,您可以检查此按钮是否不存在。

page.should_not have_xpath(:xpath, '//here your xpath to element', :text => "Login")
于 2013-11-15T19:09:44.797 回答