Skip to content

Instantly share code, notes, and snippets.

@dsci
Created December 14, 2011 10:24
Show Gist options
  • Save dsci/1476039 to your computer and use it in GitHub Desktop.
Save dsci/1476039 to your computer and use it in GitHub Desktop.
matchr_princess
Gem::Specification.new do |s|
s.name = 'matchr_princess'
s.version = '0.1'
s.platform = Gem::Platform::RUBY
s.author = 'Daniel Schmidt'
s.email = 'dsci@code79.net'
s.summary = 'Small matcher library for rspec'
s.description = 'This goes out to the marvelous novell "A princess of mars" by Edgar Rice Burroughs.'
s.files = ['matchr_princess.rb']
s.require_path = '.'
# This will added later.
s.add_development_dependency('rspec', ["~> 2.0"])
end
# Use this like:
# result = "foo"
# result.should be_equal_to "foo"
RSpec::Matchers.define :be_equal_to do |target|
match do |src|
src == target
end
end
RSpec::Matchers.define :be_status_for do |expected_status|
match do |response|
#puts response.status
response.status.to_s.include?(expected_status.to_s).should == true
end
end
RSpec::Matchers.define :be_json_for_key do |expected_json,key|
match do |response|
json = ActiveSupport::JSON::decode(response.body)
json[key.to_s].should == expected_json
end
end
RSpec::Matchers.define :have_eql_value_for_key do |key,expected_value|
match do |response|
json = ActiveSupport::JSON::decode(response.body)
json[key.to_s].should == expected_value
end
end
RSpec::Matchers.define :be_included_in do |list|
match do |src|
list.include?(src)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment