@@ -65,6 +65,61 @@ def new_record?; true; end
65
65
end
66
66
end
67
67
68
+ context "with composable matchers" do
69
+ context "one attribute is a composable matcher" do
70
+ it "passes" do
71
+ expect ( record ) . to be_a_new ( record . class ) . with (
72
+ :foo => a_string_matching ( "foo" ) )
73
+ end
74
+
75
+ it "fails" do
76
+ expect {
77
+ expect ( record ) . to be_a_new ( record . class ) . with (
78
+ :foo => a_string_matching ( "bar" ) )
79
+ } . to raise_error { |e |
80
+ expect ( e . message ) . to match ( /attribute \{ .*\} was not set on #{ Regexp . escape record . inspect } / )
81
+ expect ( e . message ) . to match ( /@expected="bar"/ )
82
+ }
83
+ end
84
+ context "matcher is wrong type" do
85
+ it "fails" do
86
+ expect {
87
+ expect ( record ) . to be_a_new ( record . class ) . with (
88
+ :foo => a_hash_including ( { :no_foo => "foo" } ) )
89
+ } . to raise_error { |e |
90
+ expect ( e . message ) . to eq ( "no implicit conversion of Hash into String" ) . or eq ( "can't convert Hash into String" )
91
+ }
92
+ end
93
+ end
94
+ end
95
+
96
+ context "two attributes are composable matchers" do
97
+ context "both matchers present in actual" do
98
+ it "passes" do
99
+ expect ( record ) . to be_a_new ( record . class ) . with (
100
+ :foo => a_string_matching ( "foo" ) ,
101
+ :bar => a_string_matching ( "bar" )
102
+ )
103
+ end
104
+ end
105
+
106
+ context "only one matcher present in actual" do
107
+ it "fails" do
108
+ expect {
109
+ expect ( record ) . to be_a_new ( record . class ) . with (
110
+ :foo => a_string_matching ( "foo" ) ,
111
+ :bar => a_string_matching ( "barn" )
112
+ )
113
+ } . to raise_error { |e |
114
+ expect ( e . message ) . to match ( /attributes \{ .*\} were not set on #{ Regexp . escape record . inspect } / )
115
+ expect ( e . message ) . to match ( /@expected="foo"/ )
116
+ expect ( e . message ) . to match ( /@expected="barn"/ )
117
+ }
118
+ end
119
+ end
120
+ end
121
+ end
122
+
68
123
context "no attributes same" do
69
124
it "fails" do
70
125
expect {
0 commit comments