Rspec Steps C0 Coverage Information - RCov

rcov/ruby/1.8/gems/rspec-expectations-2.5.0/lib/rspec/matchers/operator_matcher.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
rcov/ruby/1.8/gems/rspec-expectations-2.5.0/lib/rspec/matchers/operator_matcher.rb 87 70
70.11%
67.14%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 module RSpec
2   module Matchers
3 
4     class OperatorMatcher
5       class << self
6         def registry
7           @registry ||= {}
8         end
9 
10         def register(klass, operator, matcher)
11           registry[klass] ||= {}
12           registry[klass][operator] = matcher
13         end
14 
15         def get(klass, operator)
16           registry[klass] && registry[klass][operator]
17         end
18       end
19 
20       def initialize(actual)
21         @actual = actual
22       end
23 
24       def self.use_custom_matcher_or_delegate(operator)
25         define_method(operator) do |expected|
26           if matcher = OperatorMatcher.get(@actual.class, operator)
27             @actual.send(::RSpec::Matchers.last_should, matcher.new(expected))
28           else
29             eval_match(@actual, operator, expected)
30           end
31         end
32 
33         negative_operator = operator.sub(/^=/, '!')
34         if negative_operator != operator && respond_to?(negative_operator)
35           define_method(negative_operator) do |expected|
36             opposite_should = ::RSpec::Matchers.last_should == :should ? :should_not : :should
37             raise "RSpec does not support `#{::RSpec::Matchers.last_should} #{negative_operator} expected`.  " +
38                   "Use `#{opposite_should} #{operator} expected` instead."
39           end
40         end
41       end
42 
43       ['==', '===', '=~', '>', '>=', '<', '<='].each do |operator|
44         use_custom_matcher_or_delegate operator
45       end
46 
47       def fail_with_message(message)
48         RSpec::Expectations.fail_with(message, @expected, @actual)
49       end
50 
51       def description
52         "#{@operator} #{@expected.inspect}"
53       end
54       
55     private
56       
57       def eval_match(actual, operator, expected)
58         ::RSpec::Matchers.last_matcher = self
59         @operator, @expected = operator, expected
60         __delegate_operator(actual, operator, expected)
61       end
62 
63     end
64 
65     class PositiveOperatorMatcher < OperatorMatcher #:nodoc:
66       def __delegate_operator(actual, operator, expected)
67         if actual.__send__(operator, expected)
68           true
69         elsif ['==','===', '=~'].include?(operator)
70           fail_with_message("expected: #{expected.inspect}\n     got: #{actual.inspect} (using #{operator})") 
71         else
72           fail_with_message("expected: #{operator} #{expected.inspect}\n     got: #{operator.gsub(/./, ' ')} #{actual.inspect}")
73         end
74       end
75 
76     end
77 
78     class NegativeOperatorMatcher < OperatorMatcher #:nodoc:
79       def __delegate_operator(actual, operator, expected)
80         return false unless actual.__send__(operator, expected)
81         return fail_with_message("expected not: #{operator} #{expected.inspect}\n         got: #{operator.gsub(/./, ' ')} #{actual.inspect}")
82       end
83 
84     end
85 
86   end
87 end

Generated on Fri Apr 22 17:22:42 -0700 2011 with rcov 0.9.8