2013-07-25 5 views
0

J'utilise Ruby 1.8.7 installé sur mac osx10.8 avec l'installation de brassage et le RVM. Quand je fais bundle exec spec spec/requests/static_pages_spec.rb je reçois ces erreursRspec Failures sur Ruby 1.8.7

FFFFF.FFF 

Failures: 

    1) 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:0x104b5a108> 
    # ./spec/requests/static_pages_spec.rb:8 

    2) 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:0x104b45258> 
    # ./spec/requests/static_pages_spec.rb:13 

    3) 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:0x104b3ea48> 
    # ./spec/requests/static_pages_spec.rb:18 

    4) Static pages Help page should have the h1 'Help' 
    Failure/Error: visit help_path 
    ActionView::Template::Error: 
     undefined method `full_title' for #<#<Class:0x106d53c50>:0x106d509b0> 
    # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780' 
    # ./spec/requests/static_pages_spec.rb:26 

    5) Static pages Help page should have the title 'Help' 
    Failure/Error: visit help_path 
    ActionView::Template::Error: 
     undefined method `full_title' for #<#<Class:0x106d53c50>:0x106cde630> 
    # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780' 
    # ./spec/requests/static_pages_spec.rb:31 

    6) Static pages About page should have the title 'About Us' 
    Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us") 
    NoMethodError: 
     undefined method `has_title?' for #<Capybara::Session> 
    # ./spec/requests/static_pages_spec.rb:45 

    7) Static pages Contact page should have the content 'Contact' 
    Failure/Error: visit contact_path 
    ActionView::Template::Error: 
     undefined method `full_title' for #<#<Class:0x106d53c50>:0x106c303c8> 
    # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780' 
    # ./spec/requests/static_pages_spec.rb:52 

    8) Static pages Contact page should have the title 'Contact' 
    Failure/Error: visit contact_path 
    ActionView::Template::Error: 
     undefined method `full_title' for #<#<Class:0x106d53c50>:0x106c07298> 
    # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780' 
    # ./spec/requests/static_pages_spec.rb:57 

Finished in 0.41599 seconds 
9 examples, 8 failures 

Failed examples: 

rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the h1 'Sample App' 
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the base title 
rspec ./spec/requests/static_pages_spec.rb:17 # Static pages Home page should not have a custom page title 
rspec ./spec/requests/static_pages_spec.rb:25 # Static pages Help page should have the h1 'Help' 
rspec ./spec/requests/static_pages_spec.rb:30 # Static pages Help page should have the title 'Help' 
rspec ./spec/requests/static_pages_spec.rb:43 # Static pages About page should have the title 'About Us' 
rspec ./spec/requests/static_pages_spec.rb:51 # Static pages Contact page should have the content 'Contact' 
rspec ./spec/requests/static_pages_spec.rb:56 # Static pages Contact page should have the title 'Contact' 

Est-ce que quelqu'un sait comment résoudre une/toutes ces erreurs? voici mes fichiers associés: routes.rb

SampleApp::Application.routes.draw do 

    match '/static_pages/home', :to =>'static_pages#home' 
    match '/help' => 'static_pages#help', :via => 'get' 
    match '/about' => 'static_pages#about', :via => 'get' 
    match '/contact' => 'static_pages#contact', :via => 'get' 

    get "static_pages/home" 

    get "static_pages/help" 

    get "static_pages/about" 

    get "static_pages/contact" 

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 
     expect(page).to have_content('Sample App') 
    end 

    it "should have the base title" do 
     visit root_path 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App") 
    end 

    it "should not have a custom page title" do 
     visit root_path 
     expect(page).not_to have_title('| Home') 
    end 
    end 

    describe "Help page" do 

    it "should have the h1 'Help'" do 
     visit help_path 
     expect(page).to have_content('Help') 
    end 

    it "should have the title 'Help'" do 
     visit help_path 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help") 
    end 
    end 

    describe "About page" do 

    it "should have the h1 'About Us'" do 
     visit about_path 
     expect(page).to have_content('About Us') 
    end 

    it "should have the title 'About Us'" do 
     visit about_path 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us") 
    end 
    end 

    describe "Contact page" do 

    it "should have the content 'Contact'" do 
     visit contact_path 
     expect(page).to have_content('Contact') 
    end 

    it "should have the title 'Contact'" do 
     visit contact_path 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact") 
    end 
    end 
end 

J'ai mis à jour mon Xcode, libiconv, et tout associé. Je suis actuellement la plupart du chemin à travers le chapitre 5 du tutoriel Ruby on rails et moi pour la vie de moi ne sais pas ce qui cause ces erreurs. J'ai suivi le tutoriel parfaitement à ce jour avec les exceptions mineures telles que la modification d'une méthode du côlon dans des fusées de hachage et différentes versions de pierres précieuses, etc.

résultats rake:

s

tatic_pages_home  /static_pages/home(.:format) static_pages#home 
       help GET /help(.:format)     static_pages#help 
       about GET /about(.:format)    static_pages#about 
      contact GET /contact(.:format)    static_pages#contact 
        GET /static_pages/home(.:format) static_pages#home 
    static_pages_help GET /static_pages/help(.:format) static_pages#help 
    static_pages_about GET /static_pages/about(.:format) static_pages#about 
static_pages_contact GET /static_pages/contact(.:format) static_pages#contact 
+0

Peut vouloir réduire votre code collé à quelques exemples minimes. –

Répondre

0

Lorsque vous créez routes utilisant match et get comme ça, vous ne recevez pas les routes nommées comme help_path par défaut. Exécutez rake routes pour voir quels itinéraires sont configurés et quels sont leurs assistants nommés (le cas échéant). Vous n'avez probablement pas beaucoup de routes nommées.

Vous pouvez utiliser :as pour nommer vos itinéraires:

match '/help' => 'static_pages#help', :via => 'get', :as => 'help' 

que vous obtiendrez help_path et help_url. Si vous définissez des itinéraires en utilisant, par exemple, resources :help, beaucoup de cette magie est faite pour vous. Dans le cas de vos routes vers des actifs statiques, l'utilisation de :as est la meilleure approche.

+0

ooohhh qui a du sens, j'ai ajouté le: as => mais j'ai toujours des erreurs. Ceci est le résultat de mes routes rake: home /static_pages/home(.:format) static_pages # home help GET /help(.:format) static_pages # aide à propos de GET /about(.:format) static_pages # about contact GET /contact(.:format) ... etc – Bhetzie

+0

Pouvez-vous coller cela dans la question avec le formatage, ou faire un [gist] (https://gist.github.com/) avec le 'rake complet la sortie des routes? Ma réponse ci-dessus ne concerne que 'help_path'; vous devrez toujours définir 'root_path' et tous les autres. Si vous pouvez également publier votre fichier 'routes.rb' en entier, cela vous aidera. –

+0

Fwiw, cela n'a pas résolu mon problème –

Questions connexes