I am writing a spec to test the behavior of the mashup_controller when someone sends a query through a URL. I need to simulate the parameters contained in the URL, and i read that the post() method will do that, however when i get an error:
1) MashupController simulates query Failure/Error: post :create NoMethodError: undefined method `post' for #<RSpec::Core::ExampleGroup::Nested_1:0x980bc50> # ./mashup_controller_rspec.rb:9:in `block (2 levels) in <top (required)>' Finished in 0.20199 seconds 1 example, 1 failure Failed examples: rspec ./mashup_controller_rspec.rb:7 # MashupController simulates query
Here is my code:
require 'spec_helper' require 'mashup_controller.rb' describe MashupController do it "simulates query" do post :create end end
Sorry if I'm not making any sense. I am very new to rails and rspec. Any help would be appreciated. Thanks.
If the spec file is not under spec/controllers
, methods like get
and post
will not be automatically made available by rspec-rails
.
You either need to tag your spec:
describe MyController, type: :controller do # ... end
or include the module:
describe MyController do include RSpec::Rails::ControllerExampleGroup # ... end
See the relevant code in rspec-rails.
gem spec-rails
in your Gemfilemashup_controller_rspec.rb
should be under spec/controllers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With