realestate-com-au / akamai-rspec

Test your akamai configuration with rspec
24 stars 13 forks source link

Matchers fail with exceptions #5

Open mdub opened 8 years ago

mdub commented 8 years ago

It appears that, when akamai-rspec matchers "fail", they do so by raising an exception, e.g.

which in action looks like this:

  1) www.casa.it /vendita should not be cacheable
     Failure/Error: expect("http://#{domain}/vendita").to_not be_cacheable
     RuntimeError:
       X-Check-Cacheable header is: NO expected YES
     # /usr/local/bundle/gems/akamai_rspec-0.2.4/lib/akamai_rspec/matchers/caching.rb:52:in `x_check_cacheable'
     # /usr/local/bundle/gems/akamai_rspec-0.2.4/lib/akamai_rspec/matchers/caching.rb:7:in `block (2 levels) in <top (required)>'
     # ./spec/sample_spec.rb:18:in `block (3 levels) in <top (required)>'

I came across this while attempting to write some akamai-rspec tests for Casa (see https://git.realestate.com.au/mwilliams/casa-akamai-tests).

RSpec matchers are supposed to fail by returning false, rather than by raising exceptions.

beegibson commented 8 years ago

Thanks Mike, I didn't realise how they were meant to behave - I'll try to get to it within a week.

mdub commented 8 years ago

Thanks @biancaG. Sing out if you need any help. The RSpec documentation around defining matchers is pretty good, though; see: https://www.relishapp.com/rspec/rspec-expectations/v/2-4/docs/custom-matchers/define-matcher

Note that by design you should be able to use matchers in either a positive or negative sense, e.g.

expect(one_url).to be_cachable
expect(another_url).to_not be_cachable