我有一个控制器,我想不要有一些路线,但我得到一个奇怪的错误,无法respond to 'routable?
。
# config/routes.rb
resources :patients do
resources :encounters, except: :index
end
# encounters_controller.rb
def index
@patient = Patient.find(params[:patient_id])
@encounters = @patient.encounters.all
end
# encounters_controller_spec.rb
RSpec.describe EncountersController do
let(:valid_attributes) { Fabricate.attributes_for :encounter }
let!(:encounter) { Fabricate :encounter }
before :example do
@patient = encounter.patient
@patient_appointment = { patient_id: @patient, id: encounter }
end
it 'route' do
expect(get: '/encounters').not_to be_routeable
end
end
$ rspec spec/controllers/encounters_controller_spec.rb --backtrace
EncountersController
route (FAILED - 1)
Failures:
1) EncountersController route
Failure/Error: expect(get: '/encounters').not_to be_routeable
expected {:get=>"/encounters"} to respond to `routeable?`
# ./vendor/bundle/gems/rspec-expectations-3.1.2/lib/rspec/expectations/fail_with.rb:30:in `fail_with'
# ./vendor/bundle/gems/rspec-expectations-3.1.2/lib/rspec/expectations/handler.rb:37:in `handle_failure'
# ./vendor/bundle/gems/rspec-expectations-3.1.2/lib/rspec/expectations/handler.rb:70:in `handle_matcher'
# ./vendor/bundle/gems/rspec-expectations-3.1.2/lib/rspec/expectations/expectation_target.rb:67:in `not_to'
# ./spec/controllers/encounters_controller_spec.rb:49:in `block (2 levels) in <top (required)>'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:151:in `instance_exec'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:151:in `block in run'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:221:in `call'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:221:in `call'
# ./vendor/bundle/gems/rspec-rails-3.1.0/lib/rspec/rails/example/controller_example_group.rb:179:in `block (2 levels) in <module:ControllerExampleGroup>'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:321:in `instance_exec'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:321:in `instance_exec'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/hooks.rb:380:in `execute_with'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/hooks.rb:446:in `block (2 levels) in run'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:221:in `call'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:221:in `call'
# ./vendor/bundle/gems/rspec-rails-3.1.0/lib/rspec/rails/adapters.rb:72:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:321:in `instance_exec'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:321:in `instance_exec'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/hooks.rb:380:in `execute_with'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/hooks.rb:446:in `block (2 levels) in run'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:221:in `call'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:221:in `call'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/hooks.rb:447:in `run'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/hooks.rb:500:in `run'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:330:in `with_around_example_hooks'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example.rb:148:in `run'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example_group.rb:500:in `block in run_examples'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example_group.rb:496:in `map'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example_group.rb:496:in `run_examples'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/example_group.rb:463:in `run'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/runner.rb:111:in `block (2 levels) in run_specs'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/runner.rb:111:in `map'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/runner.rb:111:in `block in run_specs'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/reporter.rb:53:in `report'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/runner.rb:107:in `run_specs'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/runner.rb:85:in `run'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/runner.rb:69:in `run'
# ./vendor/bundle/gems/rspec-core-3.1.5/lib/rspec/core/runner.rb:37:in `invoke'
# ./vendor/bundle/gems/rspec-core-3.1.5/exe/rspec:4:in `<top (required)>'
# ./vendor/bundle/bin/rspec:23:in `load'
# ./vendor/bundle/bin/rspec:23:in `<main>'
Finished in 0.19688 seconds (files took 1.04 seconds to load)
1 example, 1 failure
尝试使用新的测试应用和支架代码时,be_routable
运行正常。我真的不明白为什么。无论我放在expect
内,我总是偶然发现routeable?
的回应。
答案 0 :(得分:1)
我认为你有一个错字......应该是:
expect(get: '/encounters').not_to be_routable
(be_routable,not be_routeable)
当我第一次尝试时,我做了同样的事情:)