spec/option_spec.rb in option-0.0.2 vs spec/option_spec.rb in option-0.0.3
- old
+ new
@@ -1,15 +1,10 @@
require "minitest/autorun"
require "minitest/spec"
-require "rr"
-require "rr/adapters/rr_methods"
-
require "option"
-include RR::Adapters::RRMethods
-
def value
12
end
describe NoneClass do
@@ -25,16 +20,14 @@
it "#get_or_else executes the block" do
None.get_or_else { "Some" }.must_equal "Some"
end
it "#foreach does not execute the block" do
- blk = proc {}
- dont_allow(blk).call
+ expected = nil
+ None.foreach { |v| expected = v }
- None.foreach(&blk)
-
- RR.verify
+ expected.must_be_nil
end
it "#or_nil should return nil" do
None.or_nil.must_be_nil
end
@@ -73,29 +66,25 @@
it "#get returns the inner value" do
Some(value).get.must_equal(value)
end
it "#get_or_else does not execute the block;" do
- blk = proc { value }
- dont_allow(blk).call
+ expected = nil
+ Some(value).get_or_else { expected = true }
- Some(value).get_or_else(&blk)
-
- RR.verify
+ expected.must_be_nil
end
it "#get_or_else returns the value" do
Some(value).get_or_else { }.must_equal(value)
end
it "#foreach executes the block passing the inner value" do
- blk = proc {}
- mock(blk).call(value)
+ expected = nil
+ Some(value).foreach { |v| expected = v }
- Some(value).foreach(&blk)
-
- RR.verify
+ expected.must_equal(value)
end
it "#or_nil should return the inner value" do
Some(value).or_nil.must_equal(value)
end
@@ -131,14 +120,14 @@
it "#fold should map the proc over the value and return it" do
Some(value).fold(proc { value * 2 }) { |v| v * 3 }.must_equal(36)
end
it "should wrap the creation of a Some" do
- mock(SomeClass).new(value)
+ Some(value).must_be_instance_of(SomeClass)
+ end
- Some(value)
-
- RR.verify
+ it "should be aliased to Some" do
+ Some.new(value).must_equal(Some(value))
end
end
describe OptionClass do