Last active
January 3, 2016 07:08
-
-
Save avsej/8426931 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyArray < Array | |
| def my_check | |
| if size > 4 | |
| :ok | |
| else | |
| :too_small | |
| end | |
| end | |
| def my_compact(use_check) | |
| if use_check && my_check != :ok | |
| self | |
| else | |
| compact | |
| end | |
| end | |
| end | |
| describe Array do | |
| subject { MyArray.new([1, nil, nil]) } | |
| before :each do | |
| subject.should_receive(:my_check).and_return(:ok) | |
| end | |
| it "doesn't remove nils for small arrays" do | |
| subject.my_compact(true) | |
| subject.should == [1, nil, nil] | |
| end | |
| context "but without use_check" do | |
| it "removes nils even for small arrays" do | |
| subject.should_not_receive(:my_check) | |
| subject.my_compact(false) | |
| end | |
| end | |
| end | |
| # $ rspec test_spec.rb | |
| # .F | |
| # | |
| # Failures: | |
| # | |
| # 1) Array but without use_check removes nils even for small arrays | |
| # Failure/Error: subject.should_receive(:my_check).and_return(:ok) | |
| # ([1, nil, nil]).my_check(any args) | |
| # expected: 1 time with any arguments | |
| # received: 0 times with any arguments | |
| # # ./test_spec.rb:23:in `block (2 levels) in <top (required)>' | |
| # | |
| # Finished in 0.00064 seconds | |
| # 2 examples, 1 failure | |
| # | |
| # Failed examples: | |
| # | |
| # rspec ./test_spec.rb:32 # Array but without use_check removes nils even for small arrays |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment