main
1require 'spec_helper'
2
3module Nasty
4 describe BlockSpecification do
5 let(:sut) { BlockSpecification.new { |item| item == true } }
6
7 context "when an item matches" do
8 it "should return true" do
9 sut.matches?(true).should be_true
10 end
11 end
12
13 context "when an item does not match" do
14 it "should return true" do
15 sut.matches?(false).should be_false
16 end
17 end
18
19 describe "or" do
20 context "when one item matches" do
21 it "should return true" do
22 sut.or(BlockSpecification.new {|x| x == false} ).matches?(false).should be_true
23 end
24 it "should return true" do
25 sut.or {|x| x == false} .matches?(false).should be_true
26 end
27 end
28
29 context "when the other item matches" do
30 it "should return true" do
31 sut.or(BlockSpecification.new {|x| x == false} ).matches?(true).should be_true
32 end
33 it "should return true" do
34 sut.or {|x| x == false} .matches?(true).should be_true
35 end
36 end
37
38 context "when neither item matches" do
39 it "should return false" do
40 sut.or(BlockSpecification.new {|x| x == true}).matches?(false).should be_false
41 end
42 it "should return false" do
43 sut.or {|x| x == true}.matches?(false).should be_false
44 end
45 end
46 end
47
48 describe "and" do
49 context "when one item matches" do
50 it "should return false" do
51 sut.and(BlockSpecification.new {|x| x == false} ).matches?(false).should be_false
52 end
53 it "should return false" do
54 sut.and {|x| x == false} .matches?(false).should be_false
55 end
56 end
57
58 context "when the other item matches" do
59 it "should return false" do
60 sut.and(BlockSpecification.new {|x| x == false} ).matches?(true).should be_false
61 end
62 it "should return false" do
63 sut.and {|x| x == false} .matches?(true).should be_false
64 end
65 end
66
67 context "when neither item matches" do
68 it "should return false" do
69 sut.and(BlockSpecification.new {|x| x == true}).matches?(false).should be_false
70 end
71 it "should return false" do
72 sut.and {|x| x == true}.matches?(false).should be_false
73 end
74 end
75
76 context "when both items match" do
77 it "should return true" do
78 sut.and(BlockSpecification.new {|x| x == true}).matches?(true).should be_true
79 end
80 it "should return true" do
81 sut.and {|x| x == true}.matches?(true).should be_true
82 end
83 end
84 end
85
86 describe "not" do
87 context "when an item matches" do
88 it "should return false" do
89 sut.not.matches?(true).should be_false
90 end
91 end
92
93 context "when an item does not match" do
94 it "should return true" do
95 sut.not.matches?(false).should be_true
96 end
97 end
98 end
99 end
100end