복붙노트

[RUBY-ON-RAILS] RSpec에와라는 이름의 경로

RUBY-ON-RAILS

RSpec에와라는 이름의 경로

나는 레일 아주 새로운 해요, 그리고 railstutorial를 따라하려고합니다. 모든 명명 된 경로 과거를 얻을 수 없습니다 내 시험을 제외하고, (5.3.3)의 벌금을 간다

내 routes.rb :

 SampleApp::Application.routes.draw do

 resources :users
 match '/signup',  to: 'users#new'

 match '/help',    to: 'static_pages#help'
 match '/about',   to: 'static_pages#about'
 match '/contact', to: 'pages#contact'

 root to: 'static_pages#home'

 #Commented stuff

내 최초 테스트 (사양 / 컨트롤러 / static_pages_controller_spec.rb) :

describe "Static pages" do

subject { page }

shared_examples_for "all static pages" do
  it { should have_selector('h1',    text: heading) }
  it { should have_selector('title', text: full_title(page_title)) }
end

describe "Home page" do
  before { visit root_path }
  let(:heading)    { 'Sample App' }
  let(:page_title) { 'Home' }

  it_should_behave_like "all static pages"
end

#Other tests

(모든 주석 물건없이)처럼 spec_helper.rb의 모습

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
    config.fixture_path = "#{::Rails.root}/spec/fixtures"
    config.use_transactional_fixtures = true
    config.infer_base_class_for_anonymous_controllers = false
end

내가 RSpec에에서 얻을 오류는 이와 같은 모든 있습니다 :

 Static pages Home page it should behave like all static pages 
 Failure/Error: before { visit root_path }
 NameError:
   undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1::Nested_1:0x00000004a12210>
 Shared Example Group: "all static pages" called from ./spec/controllers/static_pages_controller_spec.rb:17
 # ./spec/controllers/static_pages_controller_spec.rb:13:in `block (3 levels) in <top (required)>'

난 이미 사용하여 시도

 include Rails.application.routes.url_helpers

spec_helper에,하지만 내 오류를합니다 변경

 Static pages Home page it should behave like all static pages 
 Failure/Error: Unable to find matching line from backtrace
 SystemStackError:
   stack level too deep
 # /usr/lib/ruby/1.9.1/forwardable.rb:185

나는 또한 내 경로 이름을 변경의 다른 방법을 시도하지만, 그들 중 누구도 일했다. 나는 자습서 버전으로 돌아 왔어요.

정확히 문제가 무엇인지 찾는 데 도움이 될 수 있다면, 나는 레일 3.2.1, 우분투 11.10에있어 및 1.9.2p290 루비. 솔루션을 인터넷 검색을하고 ^^ '를 찾을 수 없습니다 동안 꽤을 보내고, 당신이 도움이 될 수 있습니다 희망

해결법

  1. ==============================

    1.당신이 rspec_helper.rb에 다음을 넣어 경우 명명 된 경로는 작동합니다 :

    당신이 rspec_helper.rb에 다음을 넣어 경우 명명 된 경로는 작동합니다 :

    RSpec.configure do |config|
      config.include Rails.application.routes.url_helpers
      ...
    end
    

    그것은 당신이 그것을 설정하는 방법인가?

  2. ==============================

    2.나는 당신이 당신의 RSpec에 컨트롤러 사양의 내부라는 이름의 경로에 액세스 할 수 있다고 생각하지 않습니다. 당신은 그러나 단지 root_path에 해당되는, ( '/')를 방문 할 수 있습니다.

    나는 당신이 당신의 RSpec에 컨트롤러 사양의 내부라는 이름의 경로에 액세스 할 수 있다고 생각하지 않습니다. 당신은 그러나 단지 root_path에 해당되는, ( '/')를 방문 할 수 있습니다.

  3. ==============================

    3.구글은 100 % 맞지 않는, 여기에서도 내 오류 메시지가 저를 가져왔다.

    구글은 100 % 맞지 않는, 여기에서도 내 오류 메시지가 저를 가져왔다.

    내 경우에는 카피 바라 명령은 알 수없는 visitis ...

    오류:

    NoMethodError:
           undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa49a73c>
    

    카피 바라 2.0 일 이후 폴더 사양을 사용하는 / 카피 바라 명령은 더 이상 폴더 사양 / 요청에서 일을하지 않습니다 있습니다.

    저를 도와 그 : http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html

    이 유용한을 찾아 낸다.

  4. ==============================

    4.저도 같은 자습서, 같은 문제가 있었다. 내가 그냥 Spork 서비스, 모든 가공 한 벌금을 다시 시작하기 위해 필요한 것으로 나타났다.

    저도 같은 자습서, 같은 문제가 있었다. 내가 그냥 Spork 서비스, 모든 가공 한 벌금을 다시 시작하기 위해 필요한 것으로 나타났다.

    톰 L에 의해 게시 된이 솔루션은 나를 위해 일하지만, 때 나는 또한 문제를 해결하는 것이, 그 라인 다시 시작 Spork를 제거했습니다.

    튜토리얼의 코드를 일탈에 대한 경계이다 다른 사람을 도움이되기를 바랍니다!

  5. ==============================

    5.당신은 사용해야

    당신은 사용해야

    rails generate rspec:install
    

    대신에

    rspec --init
    

    당신은 설정 파일을 수정할 수 없었을 것입니다.

    하지만 지금은하지 마 또는 응용 프로그램을 중단하고 당신이 파산 이유를 파악 좀 더 시간을 낭비해야합니다.

  6. from https://stackoverflow.com/questions/9475857/rspec-and-named-routes by cc-by-sa and MIT license