저는 레일스에 상당히 익숙하며 railstutorial을 따르려고합니다. 모든 명명 된 경로 (5.3.3)Rspec 및 명명 된 경로
과거 얻을 수없는 내 시험을 제외하고, 잘가는 내 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
나는 이미 spec_helper에
include Rails.application.routes.url_helpers
를 사용하여 시도
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)>'
하지만
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
내 오류를 변경 : 나는 RSpec에에서 얻을
오류는 이것처럼 모두 나는 또한 내 길의 이름을 바꾸는 다른 방법을 시도했지만 그들 중 누구도 일하지 않았다. 나는 튜토리얼 버전으로 돌아왔다.
정확히 어떤 문제가 있는지 찾는 데 도움이 될 수 있다면 우분투 11.10에서 레일 3.2.1과 루비 1.9.2p290을 사용하고 있습니다. 당신이 도울 수 있기를 바란다. 나는 해결책을 찾기 위해 꽤 많은 시간을 보냈고 어떤 것도 찾지 못했다. ^^ '
'config'를 제외하고 정확히 내가 한 일입니다. 부품. 모든 것이 완벽하게 작동합니다! 고마워요! – FabPelletier
누구나이 문제를 해결하고 여전히 곤란한 경우라면 root_path (etc)는 RSpec 테스트의 "describe"블록 내의 "it"섹션의 "do ... end"블록 내에서만 작동한다는 점도 주목할 가치가 있습니다 . 따라서 함수에 전달 된 경로 매개 변수를 기반으로 "it"섹션을 처리하는 함수를 만든 경우 root_path (etc)를 매개 변수로 함수에 전달할 수 없습니다. – DreadPirateShawn
레일즈 4.2 deprecastion 경고'DEPRECATION WARNING : named_routes.helpers가 더 이상 사용되지 않습니다. route_defined? (route_name)를 사용하여 이름이 지정된 라우트가 정의되었는지 확인하십시오. '이제 https를 기다릴 때까지 rspec 로그가 정리됩니다. : //github.com/rspec/rspec-rails/pull/1142를 공개해야합니다. –