Top Level Namespace

Defined Under Namespace

Modules: Speccify

Instance Method Summary collapse

Methods included from Speccify::Extension

#def_matcher, #method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Speccify::Extension

Instance Method Details

#change(&block) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/speccify.rb', line 185

def change(&block)
  Speccify::Functions::build_matcher(:change, []) do |given, matcher, args|
    before = block.call
    given.call
    after = block.call
    comparison = after != before
    if list = matcher.msgs
      comparison = case list[0].name
        # todo provide meaningful messages
      when :by          then (after == before + list[0].args[0] || after == before - list[0].args[0])
      when :by_at_least then (after >= before + list[0].args[0] || after <= before - list[0].args[0])
      when :by_at_most  then (after <= before + list[0].args[0] && after >= before - list[0].args[0])
      when :from        then (before == list[0].args[0]) && (after == list[1].args[0])
      end
    end
    matcher.positive_msg = "given block didn't alter the block attached to change, #{matcher.loc}"
    matcher.negative_msg = "given block did alter the block attached to change, #{matcher.loc}"
    comparison
  end
end