Rediver
November 26, 2012, 12:07pm
1
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:
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:
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?
qrooel
November 26, 2012, 12:56pm
2
Dawids
November 26, 2012, 1:05pm
3
Dodatkowo metoda have_content powinna posiadać argument, np.:
page.should have_content "Sample App"
Rediver
November 26, 2012, 1:26pm
4
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’
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:
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]
Rediver
November 26, 2012, 1:29pm
5
[quote=Dawids]Dodatkowo metoda have_content powinna posiadać argument, np.:
page.should have_content "Sample App"
[/quote]
dodałem i dalej wali błędem
Dawids
November 26, 2012, 1:39pm
6
@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
Rediver
November 26, 2012, 1:49pm
7
[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 ;/
Dawids
November 26, 2012, 3:03pm
9
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).
Rediver
November 27, 2012, 11:38am
10
dodałem to w configu i hmm … dalej wali błędem
[code]Failures:
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]
zlw
November 27, 2012, 11:48am
11
użyj save_and_open_page i zobacz czy na pewno wczytuje ci dobrą stronę i czy wszystko wygląda tak jak powinno
Dawids
November 27, 2012, 12:06pm
12
[quote=Rediver]dodałem to w configu i hmm … dalej wali błędem
[code]Failures:
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]
rui
November 27, 2012, 12:13pm
13
zamiast
visit '/static_pages/home.html.erb'
powinno być
visit '/static_pages/home'
Rediver
November 27, 2012, 12:43pm
14
zadziałało - wielkie dzięki - Dawids & rui