-
Notifications
You must be signed in to change notification settings - Fork 335
Testing with rspec
databyte edited this page Jun 28, 2012
·
10 revisions
Check out these resources:
- http://stackoverflow.com/questions/9576756/using-rspec-how-do-i-test-the-json-format-of-my-controller-in-rails-3-0-11
- https://github.com/nesquena/rabl/issues/130#issuecomment-5927085
In a nutshell be sure to use render_views to get tests passing:
describe ApplicationsController do
render_views
let(:model) { Factory.create(:model) }
subject { model }
context "JSON" do
describe "creating a new model" do
context "when not authorized" do
it "should not allow creation of an application" do
json = { :format => 'json', :model => { :name => "foo", :description => "bar" } }
post :create, json
Application.count.should == 0
response.status.should eq(403)
JSON.parse(response.body)["status"] == "error"
JSON.parse(response.body)["message"] =~ /authorized/
end
end
end
end
end