Top Level Namespace
- Includes:
- Speccify::Extension
Defined Under Namespace
Modules: Kernel, Speccify Classes: Object
Instance Method Summary collapse
-
#change(&block) ⇒ Object
-
lambda += 2.should change var.from(1).to(3) if var = 1.
-
-
#method_missing(name, *args, &block) ⇒ Object
be_something ===This method_missing acts as a matcher builder method.
Methods included from Speccify::Extension
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
be_something
This method_missing acts as a matcher builder method.
If a call to be_xyz() reaches this method_missing (say: obj.should be_xyz), a matcher with the name xyz will be built, whose defining property is that it returns the value of obj.xyz? for matches?.
307 308 309 310 311 312 313 314 315 |
# File 'lib/speccify.rb', line 307 def method_missing(name, *args, &block) if (name.to_s =~ /^be_(.+)/) Speccify::Functions::build_matcher(name, args) do |given, matcher, args| given.send(($1 + "?").to_sym) end else raise NoMethodError.new(name.to_s) end end |
Instance Method Details
#change(&block) ⇒ Object
-
lambda += 2.should change var.from(1).to(3) if var = 1
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/speccify.rb', line 281 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 |