Open ghost opened 8 years ago
It is probably not the btes approach, in my mind I thought it was being tested indirectly by stubbing everything and once the call arrives, everything just will work, any thoughts on this?
The call never arrives though?
controller(ApplicationController) do
include Authenticable
before_action :authenticate_with_token!
def dummy_action;end;
end
describe "#authenticate_with_token!" do
before do
routes.draw { get 'dummy_action' => 'anonymous#dummy_action' }
@user = FactoryGirl.create(:user)
allow(authentication).to receive(:current_user).and_return(nil)
get :dummy_action
end
it "returns error message as JSON" do
expect(json_response[:errors]).to eql("Not authenticated")
end
it "returns a 401 response code" do
expect(response.status).to eq(401)
end
end
This worked. Creating an anonymous controller allowed me to test whether the method existed, and returned the correct response.
That is nice, I'll include that on the second edition version of the book and make the reference to you ;)
Sweet! Much appreciated.
Specs are passing regardless of writing any code for the spec. I'm wondering why stub out the entire workings of the function, but not even call the function that is being tested.