Testy RSpec

Próbuje zrobić tesr Rspec’em i napotykam się na błąd mianowicie

w requescie w kat. spec - mam

[code]

require ‘spec_helper’

describe “Static pages” do

describe “Home page” do

it "should have the content 'Sample App'" do
  visit '/static_pages/home'
  page.should have_content
end

end
end[/code]
w widoku który rspec sprawdza jest

[code]

Sample App

This is the home page for the RoR Tut sample application.

[/code] i przy próbie sprawdzenia go
 bundle exec rspec spec/requests/static_pages_spec.rb

wali mi
błędem

[code]

F

Failures:

  1. Static pages Home page should have the content ‘Sample App’
    Failure/Error: visit ‘/static_pages/home’
    NoMethodError:
    undefined method `visit’ for #RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa24b8dc

    ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>’

Finished in 0.02804 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the content ‘Sample App’

Randomized with seed 61192

wojtek@wojtek-K73SV:~/Ruby/ws_app$ bundle exec rspec spec/requests/static_pages_spec.rb
F

Failures:

  1. Static pages Home page should have the content ‘Sample App’
    Failure/Error: visit ‘/static_pages/home’
    NoMethodError:
    undefined method `visit’ for #RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa2b9134

    ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>’

Finished in 0.03527 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the content ‘Sample App’

Randomized with seed 35246[/code]
o co kaman? ktoś wie? coś robił na rspec?

Masz tam capybare?

http://www.opinionatedprogrammer.com/2011/02/capybara-and-selenium-with-rspec-and-rails-3/

Dodatkowo metoda have_content powinna posiadać argument, np.:

page.should have_content "Sample App"

dodałem do gemfile

[code]
source ‘https://rubygems.org

gem ‘rails’, ‘3.2.9’

Bundle edge Rails instead:

gem ‘rails’, :git => ‘git://github.com/rails/rails.git’

group :development do
gem ‘sqlite3’
gem ‘rspec-rails’
gem ‘capybara’
end

Gems used only for assets and not required

in production environments by default.

group :assets do
gem ‘sass-rails’, ‘~> 3.2.3’
gem ‘coffee-rails’, ‘~> 3.2.1’

See https://github.com/sstephenson/execjs#readme for more supported runtimes

gem ‘therubyracer’, :platforms => :ruby

gem ‘uglifier’, ‘>= 1.0.3’
end

gem ‘jquery-rails’

group :production do
gem ‘pg’
end

To use ActiveModel has_secure_password

gem ‘bcrypt-ruby’, ‘~> 3.0.0’

To use Jbuilder templates for JSON

gem ‘jbuilder’

Use unicorn as the app server

gem ‘unicorn’

Deploy with Capistrano

gem ‘capistrano’

To use debugger

gem ‘debugger’[/code]

i teraz mi może krótszy błąd printuje ale dalej printuje

[code]

F

Failures:

  1. Static pages Home page should have the content ‘Sample App’
    Failure/Error: visit ‘/static_pages/home’
    NoMethodError:
    undefined method `visit’ for #RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xb36dbec

    ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>’

Finished in 0.0331 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the content ‘Sample App’

Randomized with seed 24095[/code]

[quote=Dawids]Dodatkowo metoda have_content powinna posiadać argument, np.:

page.should have_content "Sample App"

[/quote]
dodałem i dalej wali błędem

@Rediver
Rozumiem, że oprócz dodania wpisu do Gemfile, wykonałeś:

bundle install

Po za tym ten gem powinien być w grupie test:

group :test do gem 'capybara', '1.1.2' end

[quote=Dawids]@Rediver
Rozumiem, że oprócz dodania wpisu do Gemfile, wykonałeś:

bundle install

Po za tym ten gem powinien być w grupie test:

group :test do gem 'capybara', '1.1.2' end
[/quote]
dokonałem tych zmian o których wrzuciłem ten gem do grupy test i dalej błąd ;/

any idea?

Hmm… zgodnie z tym linkiem możesz spróbować dodać config.include Capybara::DSL do spec_helper.rb (w bloku RSpec.configure do |config| … end).

dodałem to w configu i hmm … dalej wali błędem

[code]Failures:

  1. static pages Zrob Test Home Page should have the content ‘Sample App’
    Failure/Error: visit ‘/static_pages/home.html.erb’
    ActionController::RoutingError:
    No route matches [GET] “/static_pages/home.html.erb”

    ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>’

Finished in 0.7071 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:7 # static pages Zrob Test Home Page should have the content ‘Sample App’

Randomized with seed 63005[/code]
podczas gdy w pliku home wyraźnie

[code]

Sample App

This is the home page for the Ruby on Rails Tutorial sample application.

[/code]

użyj save_and_open_page i zobacz czy na pewno wczytuje ci dobrą stronę i czy wszystko wygląda tak jak powinno

[quote=Rediver]dodałem to w configu i hmm … dalej wali błędem

[code]Failures:

  1. static pages Zrob Test Home Page should have the content ‘Sample App’
    Failure/Error: visit ‘/static_pages/home.html.erb’
    ActionController::RoutingError:
    No route matches [GET] “/static_pages/home.html.erb”

    ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>’

Finished in 0.7071 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:7 # static pages Zrob Test Home Page should have the content ‘Sample App’

Randomized with seed 63005[/code]
podczas gdy w pliku home wyraźnie

[code]

Sample App

This is the home page for the Ruby on Rails Tutorial sample application.

[/code] [/quote] Wygląda to tak jakby brakowało odpowiedniego wpisu w routes.rb. Powinno tam być coś takiego jak: [code=ruby]get "static_pages/home"[/code]

zamiast

visit '/static_pages/home.html.erb'

powinno być

visit '/static_pages/home'

zadziałało - wielkie dzięki - Dawids & rui