variable locale non définie ou méthode `root_path 'Tutoriel de Hartl Chapitre 5.3.2
Donc, ma première question sur Stackoverflow..... =]
Mes tests dans le Chapitre 5.3.2 de Michael Hartl du RoR Tutoriel sont tous à défaut, lorsque le tutoriel dit qu'il devrait être de passage (tutoriel dit 'a propos', 'contact', et 'help' devrait passer... mais tous les miens échec). Tout ce qui jusqu'à maintenant a bien fonctionné, mais j'ai changé le
get 'static_pages/help'
à
match '/help', to: 'static_pages#help'
de sorte que mon
config/routes.rb
SampleApp::Application.routes.draw do
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
et puis tout est allé en enfer. Tous mes tests échoue avec un undefined variable locale ou de la méthode 'root_path" ou "about_path", etc. (voir ci-dessous, la Sortie du Terminal). Mais voici mes fichiers pertinents... Juste au cas où quelqu'un est curieux, tous les fichiers sont exactement ce que Hartl. En gros, j'ai copié et collé de chaque fichier contenu.
Quelqu'un peut m'aider?????? Merci!
spec/static_pages_spec.rb
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the h1 'Sample App'" do
visit root_path
page.should have_selector('h1', text: 'Sample App')
end
it "should have the base title" do
visit root_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit root_path
page.should_not have_selector('title', text: '| Home')
end
end
describe "Help page" do
it "should have the h1 'Help'" do
visit help_path
page.should have_selector('h1', text: 'Help')
end
it "should have the title 'Help'" do
visit help_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App | Help")
end
end
describe "About page" do
it "should have the h1 'About'" do
visit about_path
page.should have_selector('h1', text: 'About Us')
end
it "should have the title 'About Us'" do
visit about_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App | About Us")
end
end
describe "Contact page" do
it "should have the h1 'Contact'" do
visit contact_path
page.should have_selector('h1', text: 'Contact')
end
it "should have the title 'Contact'" do
visit contact_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App | Contact")
end
end
end
La sortie du Terminal avec entrée rspec spec/'
FFFFFFFFF
Failures:
1) Static pages Contact page should have the h1 'Contact'
Failure/Error: visit contact_path
NameError:
undefined local variable or method `contact_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_4:0x007fd2093855f8>
# ./spec/requests/static_pages_spec.rb:55:in `block (3 levels) in <top (required)>'
2) Static pages Contact page should have the title 'Contact'
Failure/Error: visit contact_path
NameError:
undefined local variable or method `contact_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_4:0x007fd208cbeb20>
# ./spec/requests/static_pages_spec.rb:60:in `block (3 levels) in <top (required)>'
3) Static pages Help page should have the h1 'Help'
Failure/Error: visit help_path
NameError:
undefined local variable or method `help_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007fd2094c02b0>
# ./spec/requests/static_pages_spec.rb:27:in `block (3 levels) in <top (required)>'
4) Static pages Help page should have the title 'Help'
Failure/Error: visit help_path
NameError:
undefined local variable or method `help_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007fd209649208>
# ./spec/requests/static_pages_spec.rb:32:in `block (3 levels) in <top (required)>'
5) Static pages About page should have the h1 'About'
Failure/Error: visit about_path
NameError:
undefined local variable or method `about_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3:0x007fd208f16d00>
# ./spec/requests/static_pages_spec.rb:41:in `block (3 levels) in <top (required)>'
6) Static pages About page should have the title 'About Us'
Failure/Error: visit about_path
NameError:
undefined local variable or method `about_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3:0x007fd2094f7990>
# ./spec/requests/static_pages_spec.rb:46:in `block (3 levels) in <top (required)>'
7) Static pages Home page should not have a custom page title
Failure/Error: visit root_path
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fd208d30b08>
# ./spec/requests/static_pages_spec.rb:19:in `block (3 levels) in <top (required)>'
8) Static pages Home page should have the base title
Failure/Error: visit root_path
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fd208e0cb80>
# ./spec/requests/static_pages_spec.rb:13:in `block (3 levels) in <top (required)>'
9) Static pages Home page should have the h1 'Sample App'
Failure/Error: visit root_path
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fd209607268>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
Finished in 0.30216 seconds
9 examples, 9 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:54 # Static pages Contact page should have the h1 'Contact'
rspec ./spec/requests/static_pages_spec.rb:59 # Static pages Contact page should have the title 'Contact'
rspec ./spec/requests/static_pages_spec.rb:26 # Static pages Help page should have the h1 'Help'
rspec ./spec/requests/static_pages_spec.rb:31 # Static pages Help page should have the title 'Help'
rspec ./spec/requests/static_pages_spec.rb:40 # Static pages About page should have the h1 'About'
rspec ./spec/requests/static_pages_spec.rb:45 # Static pages About page should have the title 'About Us'
rspec ./spec/requests/static_pages_spec.rb:18 # Static pages Home page should not have a custom page title
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the base title
rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the h1 'Sample App'
source d'informationauteur sambaek
Vous devez vous connecter pour publier un commentaire.
Mischa réponse sera, nous l'espérons corriger la plupart de ces problèmes, mais vos tests peuvent encore échouer sur la root_path question.
Avez-vous supprimé index.html comme:
git rm public/index.html
Et n'oubliez pas de valider vos modifications avec:
git commit -am "Message"
Je vais mettre cela comme une réponse parce que la solution (de @misha) est enterré dans le les commentaires sous @marflar réponse: essayez de redémarrer Spork pour résoudre ce problème.
J'ai le même problème dans ce chapitre, il suffit de changer dans le fichier config/routes.rb racine: 'static_pages#maison" de racine : => 'static_pages#maison" et c'est de commencer à travailler. vous pouvez également vérifier toutes les routes avec râteau routes.
Dans votre Gemfile, changer la rspec-rails de la ligne:
gem 'rspec rails', 'version 2.12.0'
Cette version de rspec prend en charge l'approche Hartl est l'aide à ce point dans le livre.
fonctionne pour moi
résultats du test: 9 exemples 0 échecs
url semblent avoir changé comme ça maintenant:
Je suis en utilisant le même tutoriel et a couru dans exactement le même problème! Vous avez peut-être pensé que c'était spork qui fixe ce mais ce n'était pas elle. La raison pour laquelle il a fonctionné, c'est parce que vous êtes allé de l'avant et de mise à niveau de la Rspec dans la section suivante. Il ne fonctionne qu'avec la mise à niveau rspec - l'ancien rspec est pourquoi vos tests n'est pas passé. Le site est erroné en ce qu'il indique aux utilisateurs que les tests vont passer avant aussi la modification de la Rspec
J'ai eu un problème similaire. Ma solution était d'inclure la ligne suivante dans spec_helper.rb.rb
BTW gemmes sont:
et j'ai également retiré la Garde et de la Spork choses.