Ruby on Rails using Cucumber

Hi Everyone,

I’ve been working with cucumber trying to tests links using the scenario outline feature of cucumber. What I want to do is have it visit the starting_page and then click on the specified link. It should then check to make sure the title is correct on that page to ensure it’s on the expected page. Spent quite a bit of time googling without any luck.

Error I’ve been receiving:

expected css “title” to return something (RSpec::Expectations::ExpectationNotMetError) ./features/step_definitions/managing_pages_steps.rb:11:in `/^I should be able to change pages by clicking “([^”])" and the title is “([^”])"$/’

  features/managing_pages.feature:12:in `Then I should be able to change pages by clicking "<link>" and the title is "<title>"'

My code is below: managing_pages.feature

Scenario Outline: As a user I need links in order to navigate the site

    Given I am an anonymous user
    When I am at the "<starting_page>" page
    Then I should be able to change pages by clicking "<link>" and the title is "<title>"


    Scenarios: As a user that is not logged in
        >   starting_page |  link       |  title      |
        >    /                  | Contact  | Contact |
        >    /                  | Home     | Home    |

managing_pages_steps.rb

Given /^I am an anonymous user$/ do @user = nil end

When /^I am at the “([^”]*)" page$/ do |starting_page|

visit starting_page end

Then /^I should be able to change pages by clicking “([^”])" and the title is “([^”])"$/ do |page_name, title| click_link page_name response.should have_selector(‘title’, :content => “Contact”)

end

application_helper.rb

module ApplicationHelper

def title

base_title = "Provisioner"
if @title.nil?
  base_title
else
  "#{base_title} | #{@title}"
end

end end pages_controller.rb

class PagesController < ApplicationController def home @title = “Home”

end

def contact @title = “Contact” end end layouts/application.html.erb

<title><%= title %></title>

<%= stylesheet_link_tag :all %>

<%= javascript_include_tag :defaults %>

<%= csrf_meta_tag %>

<%= link_to "Contact", contact_path %>

<%= link_to "Home", root_path %>
<%= yield %>

Any help is much appreciated!

Hi Everyone,

I've been working with cucumber trying to tests links using the scenario outline feature of cucumber. What I want to do is have it visit the starting_page and then click on the specified link. It should then check to make sure the title is correct on that page to ensure it's on the expected page. Spent quite a bit of time googling without any luck.

Error I've been receiving:

expected css "title" to return something (RSpec::Expectations::ExpectationNotMetError) ./features/step_definitions/managing_pages_steps.rb:11:in `/^I should be able to change pages by clicking "([^"]*)" and the title is "([^"]*)"$/' features/managing_pages.feature:12:in `Then I should be able to change pages by clicking "<link>" and the title is "<title>"'

My code is below:

managing_pages.feature

Scenario Outline: As a user I need links in order to navigate the site Given I am an anonymous user When I am at the "<starting_page>" page Then I should be able to change pages by clicking "<link>" and the title is "<title>"

    Scenarios: As a user that is not logged in
        &gt;   starting\_page |  link       |  title      |
        &gt;    /                  | Contact  | Contact |
        &gt;    /                  | Home     | Home    |

managing_pages_steps.rb

Given /^I am an anonymous user$/ do @user = nil end

When /^I am at the "([^"]*)" page$/ do |starting_page| visit starting_page end

Then /^I should be able to change pages by clicking "([^"]*)" and the title is "([^"]*)"$/ do |page_name, title| click_link page_name response.should have_selector('title', :content => "Contact") end

application_helper.rb

module ApplicationHelper

def title base_title = "Provisioner" if @title.nil? base_title else "#{base_title} | #{@title}" end end end

pages_controller.rb

class PagesController < ApplicationController def home @title = "Home" end

def contact @title = "Contact" end end

layouts/application.html.erb

<!DOCTYPE html> <html> <head> <title><%= title %></title> <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %> <%= link_to "Contact", contact_path %> <%= link_to "Home", root_path %> </head> <body>

&lt;%= yield %&gt;

</body> </html>

Any help is much appreciated!

You're getting this error

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

Webrat is expecting a <title> html tag. You're usign have_selector and you're specifying a tagname. Do you have something like <title>Contact</title> in that page?

Ya, it’s in the layout.

<%= title %>

which uses the application helper application_helper.rb

module ApplicationHelper

def title

base_title = "Provisioner"
if @title.nil?
  base_title
else
  "#{base_title} | #{@title}"
end

end end

which gets the @title from the pages controller