3

特徴

Scenario: As a user that has not signed in I want to be able to sign up for provisioner
        Given I am not logged in
        When I go to the home page
        And click on the "Sign Up" button
        Then I should be on the page with the title: "Sign Up"
        When I provide valid information
        And click the "Submit" button
        Then I should see "Account is being created and verified, you will receive an   email with instructions once account has been approved"
        And the application should send the administrator an email
        And I should be redirected to the home page as an anonymous user

手順

When /^I go to the home page$/ do
  visit root_path
end

When /^click on the "([^"]*)" button$/ do |page_name|
  click_link page_name
end

Then /^I should be on the page with the title: "([^"]*)"$/ do |page_title|
  response.should have_selector('title', :content => "#{page_title}")
end

エラー

expected css "title" to return something (RSpec::Expectations::ExpectationNotMetError)

Thenステップで失敗しますが、手動でページに移動すると、「サインアップ」というタイトルでページがレンダリングされます。テストで正しい場所に行くことを確認したいのです。どうすればチェックできますか?

事前にご協力いただきありがとうございます。

4

4 に答える 4

6

これを試して:

page.should have_css('head title', :text => title)

于 2011-07-27T07:35:26.900 に答える
3

2.1以降、それを行うことができます:

expect(page).to have_title "my_title"

于 2013-08-22T11:55:56.697 に答える
0

これは、デフォルトでカピバラセレクターが次のようにCSS変更しようとするように設定されているために発生する可能性があります

response.should have_xpath('//title', :text => "#{page_title}")
于 2011-07-27T07:36:13.440 に答える
0

cucumber-rails gem を使用している場合は、使用してみてください

assert page.has_title?(page_title), "page has title of '#{page.title}'"
于 2016-03-01T18:38:13.820 に答える