travis-api/spec/support/matchers.rb
Brian Ford 51a07c892b Update spec/support/matchers.rb
Rubinius does not yet destructure block (or method) arguments in 1.9 mode. This change makes the specs pass on Rubinius. It's not clear to me why destructering is being used here. Ruby will already destructure a single Array-ish argument into separate block argument locals. In this case, unless you want, give `a, b` passed, `name, content = a` and NOT `name, content = a, b`, the unparenthesized (ie non-extra-level-destructuring) should work fine. If that makes any sense. :)
2012-10-11 14:58:45 -07:00

63 lines
1.6 KiB
Ruby

# TODO move to travis-core?
RSpec::Matchers.define :deliver_json_for do |resource, options = {}|
match do |response|
if response.status == 200
actual = parse(response.body)
expected = Travis::Api.data(resource, options)
failure_message_for_should do
"expected\n\n#{actual}\n\nto equal\n\n#{expected}"
end
actual == expected
else
failure_message_for_should do
"expected the request to be successful (200) but was #{response.status}"
end
false
end
end
def parse(body)
MultiJson.decode(body)
end
end
RSpec::Matchers.define :deliver_result_image_for do |name|
match do |response|
actual = files.detect do |name, content|
response.body.to_s.force_encoding('ascii') == content.to_s.force_encoding('ascii') # TODO ummmmmmmm?
end
actual = actual && actual[0]
failure_message_for_should do
"expected #{actual.inspect} to equal #{name.inspect}"
end
actual == name
end
def files
files = Hash[*Dir['public/images/result/*.png'].map do |file|
[File.basename(file, '.png'), File.read(file)]
end.flatten]
end
end
RSpec::Matchers.define :redirect_to do |expected|
match do |response|
actual = response.headers['location'].to_s.sub('http://example.org', '')
failure_message_for_should do
"expected to be redirect to #{expected} but was not. status: #{response.status}, location: #{actual}"
end
failure_message_for_should_not do
"expected not to be redirect to #{expected} but was."
end
actual == expected
end
end