4
4
class TestError < StandardError ; end
5
5
class AnotherTestError < StandardError ; end
6
6
7
- it "has an reports_error alias " do
7
+ it "is aliased as reports_error " do
8
8
expect { Rails . error . report ( StandardError . new ( "test error" ) ) } . to reports_error
9
9
end
10
10
11
- it "warns that passing value expectation doesn't work " do
11
+ it "warns when used as a value expectation " do
12
12
expect {
13
13
expect ( Rails . error . report ( StandardError . new ( "test error" ) ) ) . to have_reported_error
14
14
} . to raise_error ( ArgumentError , "this matcher doesn’t work with value expectations" )
15
15
end
16
16
17
- describe "basic functionality " do
17
+ context "without constraint " do
18
18
it "passes when an error is reported" do
19
19
expect { Rails . error . report ( StandardError . new ( "test error" ) ) } . to have_reported_error
20
20
end
21
21
22
- it "fails when no error is reported" do
22
+ it "fails when no errors are reported" do
23
23
expect {
24
24
expect { "no error" } . to have_reported_error
25
25
} . to fail_with ( /Expected the block to report an error, but none was reported./ )
26
26
end
27
27
28
- it "passes when negated and no error is reported" do
28
+ it "passes when negated and no errors are reported" do
29
29
expect { "no error" } . not_to have_reported_error
30
30
end
31
31
end
32
32
33
- describe " error class matching " do
34
- it "passes when correct error class is reported" do
33
+ context "constrained to a specific error class" do
34
+ it "passes when an error with the correct class is reported" do
35
35
expect { Rails . error . report ( TestError . new ( "test error" ) ) } . to have_reported_error ( TestError )
36
36
end
37
37
38
- it "fails when wrong error class is reported" do
38
+ it "fails when an error with the wrong class is reported" do
39
39
expect {
40
40
expect {
41
41
Rails . error . report ( AnotherTestError . new ( "wrong error" ) )
@@ -44,20 +44,20 @@ class AnotherTestError < StandardError; end
44
44
end
45
45
end
46
46
47
- describe "error instance matching" do
48
- it "passes when error instance matches exactly" do
47
+ context "constrained to a matching error (class and message) " do
48
+ it "passes with an error that matches exactly" do
49
49
expect {
50
50
Rails . error . report ( TestError . new ( "exact message" ) )
51
51
} . to have_reported_error ( TestError . new ( "exact message" ) )
52
52
end
53
53
54
- it "passes when error instance has empty expected message" do
54
+ it "passes any error of the same class if the expected message is empty " do
55
55
expect {
56
56
Rails . error . report ( TestError . new ( "any message" ) )
57
57
} . to have_reported_error ( TestError . new ( "" ) )
58
58
end
59
59
60
- it "fails when error instance has different message" do
60
+ it "fails when the error has different message to the expected " do
61
61
expect {
62
62
expect {
63
63
Rails . error . report ( TestError . new ( "actual message" ) )
@@ -66,14 +66,14 @@ class AnotherTestError < StandardError; end
66
66
end
67
67
end
68
68
69
- describe " regex pattern matching" do
70
- it "passes when error message matches pattern" do
69
+ context "constrained by regex pattern matching" do
70
+ it "passes when an error message matches the pattern" do
71
71
expect {
72
72
Rails . error . report ( StandardError . new ( "error with pattern" ) )
73
73
} . to have_reported_error ( /with pattern/ )
74
74
end
75
75
76
- it "fails when error message does not match pattern" do
76
+ it "fails when no error messages match the pattern" do
77
77
expect {
78
78
expect {
79
79
Rails . error . report ( StandardError . new ( "error without match" ) )
@@ -82,8 +82,8 @@ class AnotherTestError < StandardError; end
82
82
end
83
83
end
84
84
85
- describe "failure messages for attribute mismatches " do
86
- it "provides detailed failure message when attributes don't match " do
85
+ describe "#failure_message " do
86
+ it "provides details about mismatched attributes" do
87
87
expect {
88
88
expect {
89
89
Rails . error . report ( StandardError . new ( "test" ) , context : { user_id : 123 , context : "actual" } )
@@ -116,7 +116,7 @@ class AnotherTestError < StandardError; end
116
116
end
117
117
end
118
118
119
- describe "attribute matching with .with chain " do
119
+ describe "# with" do
120
120
it "passes when attributes match exactly" do
121
121
expect {
122
122
Rails . error . report ( StandardError . new ( "test" ) , context : { user_id : 123 , context : "test" } )
0 commit comments