Reputation: 11639
I have seen some examples of this error, and tried a lot of things but none of them work for me.
Test in Rspec:
it "should load data of invoices" do
post :Invoices , taxiNo: "T2"
expect(response.status).to eq(201)
end
Routes:
post "/Invoices", :to => "taxidriver#getInvoices"
Controller:
class TaxidriverController < ApplicationController
def getInvoices
render :text => {:message => "A new Taxi created"}.to_json, :status => :created
end
end
I am not sure about the line post :Invoices , taxiNo: "T2"
Should I hit the url ? or should I hit the method?
I also tried post :getInvoices, taxiNo: "T2"
but still the same error:
ActionController::UrlGenerationError:
No route matches {:action=>"Invoices", :controller=>"bookings", :taxiNo=>"T2"}
# ./spec/controllers/bookings_spec.rb:50:in `block (3 levels) in <top (required)>'
Upvotes: 2
Views: 2201
Reputation: 4639
The specific error your currently getting about "no route matches" is because you wrote your spec like this ...
post :Invoices , taxiNo: "T2"
When according to your routes and controller you named the method "getInvoices"
So you need to change your spec to this
post :getInvoices , taxiNo: "T2"
Upvotes: 3