Skip to content

Instantly share code, notes, and snippets.

@ticktricktrack
Created October 26, 2012 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ticktricktrack/3959775 to your computer and use it in GitHub Desktop.
Save ticktricktrack/3959775 to your computer and use it in GitHub Desktop.
APIMatchers example specs
### Gemfile
source 'https://rubygems.org'
gem 'rspec', '2.11.0'
gem 'api_matchers', '0.1.1'
### spec
require 'api_matchers'
include APIMatchers::RSpecMatchers
describe "APIMatcher examples" do
it "shouldn't fail" do
"{ 'transaction': { 'id': '54', 'status': 'paid' } }".should have_node(:transaction)
end
it "also shouldn't fail" do
"{ 'transaction': { 'id': '54', 'status': 'paid' } }".should have_node(:id).with(54)
end
it "passes" do
'{"error": "Transaction error: Name cant be blank"}'.should have_node(:error).including_text("Transaction error")
end
it "passes too" do
'{"creditcard":true}'.should have_node(:creditcard).with(true)
end
end
###
rspec api_matchers_spec.rb
FF..
Failures:
1) APIMatcher examples shouldn't fail
Failure/Error: "{ 'transaction': { 'id': '54', 'status': 'paid' } }".should have_node(:transaction)
expected to have node called: 'transaction'. Got: '{ 'transaction': { 'id': '54', 'status': 'paid' } }'
# ./api_matchers_spec.rb:6:in `block (2 levels) in <top (required)>'
2) APIMatcher examples also shouldn't fail
Failure/Error: "{ 'transaction': { 'id': '54', 'status': 'paid' } }".should have_node(:id).with(54)
expected to have node called: 'id' with value: '54'. Got: '{ 'transaction': { 'id': '54', 'status': 'paid' } }'
# ./api_matchers_spec.rb:10:in `block (2 levels) in <top (required)>'
Finished in 0.00822 seconds
4 examples, 2 failures
Failed examples:
rspec ./api_matchers_spec.rb:5 # APIMatcher examples shouldn't fail
rspec ./api_matchers_spec.rb:9 # APIMatcher examples also shouldn't fail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment