Topic: Rails tests failing

if i write the test like this its working just fine it passes green

it "should have the right title" do
        get 'view'
        response.should have_selector('title',
                                     :content => "View Snippets")
    end

but for the same page this format its red, they shold test for the same thing?
http://dl.dropbox.com/u/15024055/CloudS … 232654.png

require 'spec_helper'

describe "SnippetsPages" do

    describe "New Snippet pages" do
        before { get 'new'}

        it { should have_selector('h1', content: 'New') }
        it { should have_selector('title', content: full_title('New Snippet')) }
    end


    describe "View Snippets pages" do
        before { get 'view' }

        it { should have_selector('h1', content: 'View') }
        it { should have_selector('title', content: full_title('View Snippets')) }
    end
end

I can't understand why my tests is not working Here is the helper:


def full_title(page_title)
    base_title = "Sample App"
    if page_title.empty?
        base_title
    else
        page_title
    end
end

ErrorMessage

Failures:

  1) SnippetsPages New Snippet pages
     Failure/Error: it { should have_selector('h1', content: 'New') }
       expected following output to contain a <h1>New</h1> tag:
       <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
       <html><body><p>New Snippet pages</p></body></html>
     # ./spec/requests/snippets_pages_spec.rb:8:in `block (3 levels) in <top (required)>'

  2) SnippetsPages New Snippet pages
     Failure/Error: it { should have_selector('title', content: full_title('New Snippet')) }
       expected following output to contain a <title>Ruby on Rails Tutorial Sample App | New Snippet</title> tag:
       <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
       <html><body><p>New Snippet pages</p></body></html>
     # ./spec/requests/snippets_pages_spec.rb:9:in `block (3 levels) in <top (required)>'

  3) SnippetsPages View Snippets pages
     Failure/Error: it { should have_selector('h1', content: 'View') }
       expected following output to contain a <h1>View</h1> tag:
       <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
       <html><body><p>View Snippets pages</p></body></html>
     # ./spec/requests/snippets_pages_spec.rb:16:in `block (3 levels) in <top (required)>'

  4) SnippetsPages View Snippets pages
     Failure/Error: it { should have_selector('title', content: full_title('View Snippets')) }
       expected following output to contain a <title>Ruby on Rails Tutorial Sample App | View Snippets</title> tag:
       <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
       <html><body><p>View Snippets pages</p></body></html>
     # ./spec/requests/snippets_pages_spec.rb:17:in `block (3 levels) in <top (required)>'

Finished in 1.12 seconds
11 examples, 4 failures

Failed examples:

rspec ./spec/requests/snippets_pages_spec.rb:8 # SnippetsPages New Snippet pages
rspec ./spec/requests/snippets_pages_spec.rb:9 # SnippetsPages New Snippet pages
rspec ./spec/requests/snippets_pages_spec.rb:16 # SnippetsPages View Snippets pages
rspec ./spec/requests/snippets_pages_spec.rb:17 # SnippetsPages View Snippets pages

--Versions--

➜  sample_app git:(modeling-users) ✗ rails -v
Rails 3.1.3

➜  sample_app git:(modeling-users) ✗ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]

➜  sample_app git:(modeling-users) ✗ rspec -v
2.6.4

--End Versions--

This is some code.

gemfile

gemfile

source 'http://rubygems.org'

gem 'rails', '3.1.3'
gem 'bootstrap-sass', '2.0.0'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.1.5'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :development do
    gem 'rspec-rails'
    gem 'spork'
    gem 'guard-rspec', '0.5.5'
    gem 'annotate', '~> 2.4.1.beta'
end

group :test do
    gem 'rspec-rails'
    gem 'spork'
    gem 'webrat'
    gem 'capybara', '1.1.2'
    gem 'rb-inotify', '0.8.8'
    gem 'libnotify', '0.5.9'
end