2013-09-24 4 views
2

У меня есть этот простой эшафот:Простой Эшафот ставит: ActionView :: Template :: Ошибка: неопределенный метод `edit_user_path»

RSpec:

require 'spec_helper' 

describe "users/show" do 
    before(:each) do 
    @user = assign(:user, stub_model(User, 
     :first_name => "First Name", 
     :last_name => "Last Name" 
    )) 
    end 

    it "renders attributes in <p>" do 
    render 
    # Run the generator again with the --webrat flag if you want to use webrat matchers 
    rendered.should match(/First Name/) 
    rendered.should match(/Last Name/) 
    end 
end 

пользователей/show.html.erb :

<p id="notice"><%= notice %></p> 

<p> 
    <b>First name:</b> 
    <%= @user.first_name %> 
</p> 

<p> 
    <b>Last name:</b> 
    <%= @user.last_name %> 
</p> 

<%= link_to 'Edit', edit_user_path(@user) %> | 

routes.rb

resources :users 

реки маршруты говорит маршруты существуют для пользователей

   users GET /users(.:format)      users#index 
        POST /users(.:format)      users#create 
      new_user GET /users/new(.:format)     users#new 
      edit_user GET /users/:id/edit(.:format)   users#edit 
       user GET /users/:id(.:format)     users#show 
        PUT /users/:id(.:format)     users#update 
        DELETE /users/:id(.:format)     users#destroy 

На любой модели я бег RSpec ставит

ActionView::Template::Error: undefined method `edit_user_path' for #<#<Class:0x007fc99a517cd0>:0x007fc99a577c20> 
./app/views/users/show.html.erb:14:in 

Что случилось с моим кодом?

Вот мой spec_helper.rb

require 'rubygems' 
require 'spork' 
#uncomment the following line to use spork with the debugger 
#require 'spork/ext/ruby-debug' 

Spork.prefork do 
    require 'rspec/rails' 
    require 'rspec/autorun' 
    require 'capybara/rspec' 
    require 'capybara/rails' 
    require "shoulda" 
    require 'database_cleaner' 

    # This file is copied to spec/ when you run 'rails generate rspec:install' 
    ENV["RAILS_ENV"] ||= 'test' 
    require File.expand_path("../../config/environment", __FILE__) 


    # Requires supporting ruby files with custom matchers and macros, etc, 
    # in spec/support/ and its subdirectories. 
    Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } 

    RSpec.configure do |config| 
    # ## Mock Framework 
    # 
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 
    # 
    # config.mock_with :mocha 
    # config.mock_with :flexmock 
    # config.mock_with :rr 
    config.mock_with :rspec 

    config.include JsonSpec::Helpers 

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 
    config.fixture_path = "#{::Rails.root}/spec/fixtures" 

    # If you're not using ActiveRecord, or you'd prefer not to run each of your 
    # examples within a transaction, remove the following line or assign false 
    # instead of true. 
    config.use_transactional_fixtures = false 

    # If true, the base class of anonymous controllers will be inferred 
    # automatically. This will be the default behavior in future versions of 
    # rspec-rails. 
    config.infer_base_class_for_anonymous_controllers = false 

    # Run specs in random order to surface order dependencies. If you find an 
    # order dependency and want to debug it, you can fix the order by providing 
    # the seed, which is printed after each run. 
    #  --seed 1234 
    config.order = "random" 

    DatabaseCleaner.strategy = :truncation 
    DatabaseCleaner.orm = "active_record" 

    config.before(:suite) do 
     DatabaseCleaner.clean 
     DatabaseCleaner.strategy = :transaction 
     DatabaseCleaner.clean_with(:truncation) 
    end 

    config.before(:each) do 
     DatabaseCleaner.start 
    end 

    config.after(:each) do 
     DatabaseCleaner.clean 
    end 
    end 
end 

Spork.each_run do 
    # This code will be run each time you run your specs. 
    # Fabrication.clear_definitions 
    # Dir[Rails.root.join("spec/fabricators/**/*.rb")].each{|f| load f} 
    DatabaseCleaner.clean 

    Fabrication.clear_definitions 

    Dir["#{Rails.root}/app/models/**/*.rb", "#{Rails.root}/app/services/**/*.rb", "#{Rails.root}/app/admin/**/*.rb","#{Rails.root}/app/mailers/**/*.rb"].each do |model| 
    load model 
    end 
end 
+0

Это длинный снимок, но вы пытались перепечатать все символы вокруг 'edit_user_path' в вашем файле' .html', если в нем будут прокручиваться символы пробела нулевой ширины? –

+0

Кроме того, вы намеревались включить символ '|' в конец вашего файла .html? –

+0

Кроме того, выполняйте какие-либо другие характеристики вашего запуска в порядке? Есть ли у вас какие-либо взгляды с путями в них, которые «работают» в rspec? Работает ли это представление при запуске Rails? –

ответ

3

Через час болтал с Питером. Проблема заключалась в порядке требований в spec_helper.rb.

Что было первым:

require 'rspec/rails' 
require 'rspec/autorun' 

require 'capybara/rspec' 
require 'capybara/rails' 
require "shoulda" 
require 'database_cleaner' 

# This file is copied to spec/ when you run 'rails generate rspec:install' 
ENV["RAILS_ENV"] ||= 'test' 
require File.expand_path("../../config/environment", __FILE__) 

к этому:

# This file is copied to spec/ when you run 'rails generate rspec:install' 
ENV["RAILS_ENV"] ||= 'test' 
require File.expand_path("../../config/environment", __FILE__) 

require 'rspec/rails' 
require 'rspec/autorun' 

require 'capybara/rspec' 
require 'capybara/rails' 
require "shoulda" 
require 'database_cleaner' 

Таким образом, кажется, что ENV и config/environment должен быть загружен первым.

Спасибо, что получили этот пробег.

+1

+1 :-) Кроме того, ссылка на http://stackoverflow.com/questions/9475857/rspec-and-named-routes/11935770#11935770 в случае, если кто-то другой столкнется с этой ситуацией и найдет другой вопрос. –

+0

Ницца найти, Питер. –

+0

Около миллиона спасибо за это @jan. –

 Смежные вопросы

  • Нет связанных вопросов^_^