Skip to content

Instantly share code, notes, and snippets.

@rafbm
Forked from remi/reports_controller_spec.rb
Last active December 14, 2015 03:19
Show Gist options
  • Save rafbm/5019918 to your computer and use it in GitHub Desktop.
Save rafbm/5019918 to your computer and use it in GitHub Desktop.
describe ReportsController do
describe :create do
before do
@payload = { :version => "1.0.0" }
end
it "succeeds with present serial" do
@payload[:serial] = "123abc"
post reports_path, @payload.to_json
last_response.should be_ok
last_response.status.should eq 200
end
it "fails with missing serial" do
@payload[:serial] = nil
post reports_path, @payload.to_json
last_response.should_not be_ok
last_response.status.should eq 400
end
end
end
@rafbm
Copy link
Author

rafbm commented Feb 23, 2013

…srait le fun que les comments de gists s’updatent automagiquement comme les issues…

@rafbm
Copy link
Author

rafbm commented Feb 23, 2013

Toujours possible de faire ça si t’as une shitload d’expectations :

it "fails with missing serial" do
  @payload[:serial] = nil
  post reports_path, @payload.to_json

  last_response.instance_eval do
    should_not be_ok
    status.should eq 400
    JSON.parse(body)["errors"].should include?("Missing serial number")
  end
end

__evil laugh**

@remi
Copy link

remi commented Feb 23, 2013

Dans cet exemple, est-ce que RSpec roule le before avant le it et avant le its ?

Yep. Le before est exécuté une fois avant le it et une fois avant le its.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment