rspec-expectations 2.0.0.beta.22 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/.gitignore +1 -1
  2. data/.travis.yml +7 -0
  3. data/Gemfile +35 -13
  4. data/Guardfile +5 -0
  5. data/License.txt +1 -1
  6. data/README.md +43 -0
  7. data/Rakefile +51 -9
  8. data/cucumber.yml +9 -2
  9. data/features/.nav +29 -0
  10. data/features/Changelog.md +101 -0
  11. data/features/README.markdown +45 -8
  12. data/features/built_in_matchers/README.md +71 -0
  13. data/features/built_in_matchers/be.feature +135 -0
  14. data/features/built_in_matchers/be_within.feature +43 -0
  15. data/features/built_in_matchers/cover.feature +45 -0
  16. data/features/{matchers → built_in_matchers}/equality.feature +16 -13
  17. data/features/built_in_matchers/exist.feature +43 -0
  18. data/features/built_in_matchers/expect_change.feature +59 -0
  19. data/features/built_in_matchers/expect_error.feature +105 -0
  20. data/features/built_in_matchers/have.feature +103 -0
  21. data/features/built_in_matchers/include.feature +121 -0
  22. data/features/built_in_matchers/match.feature +50 -0
  23. data/features/built_in_matchers/operators.feature +221 -0
  24. data/features/built_in_matchers/predicates.feature +128 -0
  25. data/features/built_in_matchers/respond_to.feature +78 -0
  26. data/features/built_in_matchers/satisfy.feature +31 -0
  27. data/features/built_in_matchers/throw_symbol.feature +85 -0
  28. data/features/built_in_matchers/types.feature +114 -0
  29. data/features/{matchers → custom_matchers}/access_running_example.feature +2 -2
  30. data/features/{matchers → custom_matchers}/define_diffable_matcher.feature +1 -1
  31. data/features/{matchers → custom_matchers}/define_matcher.feature +91 -9
  32. data/features/{matchers → custom_matchers}/define_matcher_outside_rspec.feature +1 -1
  33. data/features/{matchers → custom_matchers}/define_matcher_with_fluent_interface.feature +8 -11
  34. data/features/customized_message.feature +22 -0
  35. data/features/{expectations/diffing.feature → diffing.feature} +16 -16
  36. data/features/{expectations/implicit_docstrings.feature → implicit_docstrings.feature} +4 -4
  37. data/features/step_definitions/additional_cli_steps.rb +22 -0
  38. data/features/support/env.rb +5 -1
  39. data/features/test_frameworks/test_unit.feature +46 -0
  40. data/lib/rspec/expectations/backward_compatibility.rb +22 -1
  41. data/lib/rspec/expectations/deprecation.rb +36 -0
  42. data/lib/rspec/expectations/extensions.rb +0 -1
  43. data/lib/rspec/expectations/version.rb +1 -1
  44. data/lib/rspec/expectations.rb +2 -1
  45. data/lib/rspec/matchers/be.rb +4 -4
  46. data/lib/rspec/matchers/be_close.rb +2 -17
  47. data/lib/rspec/matchers/be_within.rb +40 -0
  48. data/lib/rspec/matchers/block_aliases.rb +19 -0
  49. data/lib/rspec/matchers/change.rb +74 -49
  50. data/lib/rspec/matchers/cover.rb +35 -0
  51. data/lib/rspec/matchers/exist.rb +13 -3
  52. data/lib/rspec/matchers/has.rb +15 -11
  53. data/lib/rspec/matchers/have.rb +5 -5
  54. data/lib/rspec/matchers/include.rb +14 -5
  55. data/lib/rspec/matchers/matcher.rb +39 -13
  56. data/lib/rspec/matchers/method_missing.rb +6 -3
  57. data/lib/rspec/matchers/operator_matcher.rb +12 -3
  58. data/lib/rspec/matchers/respond_to.rb +23 -9
  59. data/lib/rspec/matchers/satisfy.rb +4 -0
  60. data/lib/rspec/matchers/throw_symbol.rb +43 -26
  61. data/lib/rspec/matchers.rb +15 -3
  62. data/rspec-expectations.gemspec +2 -6
  63. data/spec/rspec/matchers/be_close_spec.rb +11 -39
  64. data/spec/rspec/matchers/be_spec.rb +8 -8
  65. data/spec/rspec/matchers/be_within_spec.rb +64 -0
  66. data/spec/rspec/matchers/change_spec.rb +88 -9
  67. data/spec/rspec/matchers/cover_spec.rb +65 -0
  68. data/spec/rspec/matchers/description_generation_spec.rb +41 -25
  69. data/spec/rspec/matchers/exist_spec.rb +90 -51
  70. data/spec/rspec/matchers/has_spec.rb +2 -2
  71. data/spec/rspec/matchers/have_spec.rb +291 -291
  72. data/spec/rspec/matchers/include_spec.rb +318 -65
  73. data/spec/rspec/matchers/matcher_spec.rb +91 -0
  74. data/spec/rspec/matchers/matchers_spec.rb +29 -0
  75. data/spec/rspec/matchers/method_missing_spec.rb +23 -0
  76. data/spec/rspec/matchers/operator_matcher_spec.rb +36 -10
  77. data/spec/rspec/matchers/respond_to_spec.rb +177 -1
  78. data/spec/rspec/matchers/satisfy_spec.rb +4 -0
  79. data/spec/rspec/matchers/throw_symbol_spec.rb +27 -10
  80. data/spec/spec_helper.rb +10 -35
  81. data/spec/support/classes.rb +1 -1
  82. data/spec/support/matchers.rb +22 -0
  83. data/spec/support/ruby_version.rb +10 -0
  84. metadata +95 -114
  85. data/History.md +0 -16
  86. data/README.markdown +0 -23
  87. data/features/expectations/attribute_of_subject.feature +0 -19
  88. data/features/expectations/customized_message.feature +0 -54
  89. data/features/matchers/expect_change.feature +0 -65
  90. data/features/matchers/expect_error.feature +0 -44
  91. data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +0 -19
  92. data/spec/suite.rb +0 -1
  93. /data/{Upgrade.markdown → features/Upgrade.md} +0 -0
@@ -9,42 +9,42 @@ describe "Matchers should be able to generate their own descriptions" do
9
9
  "this".should == "this"
10
10
  RSpec::Matchers.generated_description.should == "should == \"this\""
11
11
  end
12
-
12
+
13
13
  it "should not == expected" do
14
14
  "this".should_not == "that"
15
15
  RSpec::Matchers.generated_description.should == "should not == \"that\""
16
16
  end
17
-
17
+
18
18
  it "should be empty (arbitrary predicate)" do
19
19
  [].should be_empty
20
20
  RSpec::Matchers.generated_description.should == "should be empty"
21
21
  end
22
-
22
+
23
23
  it "should not be empty (arbitrary predicate)" do
24
24
  [1].should_not be_empty
25
25
  RSpec::Matchers.generated_description.should == "should not be empty"
26
26
  end
27
-
27
+
28
28
  it "should be true" do
29
29
  true.should be_true
30
30
  RSpec::Matchers.generated_description.should == "should be true"
31
31
  end
32
-
32
+
33
33
  it "should be false" do
34
34
  false.should be_false
35
35
  RSpec::Matchers.generated_description.should == "should be false"
36
36
  end
37
-
37
+
38
38
  it "should be nil" do
39
39
  nil.should be_nil
40
40
  RSpec::Matchers.generated_description.should == "should be nil"
41
41
  end
42
-
42
+
43
43
  it "should be > n" do
44
44
  5.should be > 3
45
45
  RSpec::Matchers.generated_description.should == "should be > 3"
46
46
  end
47
-
47
+
48
48
  it "should be predicate arg1, arg2 and arg3" do
49
49
  5.0.should be_between(0,10)
50
50
  RSpec::Matchers.generated_description.should == "should be between 0 and 10"
@@ -55,42 +55,58 @@ describe "Matchers should be able to generate their own descriptions" do
55
55
  expected.should equal(expected)
56
56
  RSpec::Matchers.generated_description.should == "should equal \"expected\""
57
57
  end
58
-
58
+
59
59
  it "should_not equal" do
60
60
  5.should_not equal(37)
61
61
  RSpec::Matchers.generated_description.should == "should not equal 37"
62
62
  end
63
-
63
+
64
64
  it "should eql" do
65
65
  "string".should eql("string")
66
66
  RSpec::Matchers.generated_description.should == "should eql \"string\""
67
67
  end
68
-
68
+
69
69
  it "should not eql" do
70
70
  "a".should_not eql(:a)
71
71
  RSpec::Matchers.generated_description.should == "should not eql :a"
72
72
  end
73
-
73
+
74
74
  it "should have_key" do
75
75
  {:a => "a"}.should have_key(:a)
76
76
  RSpec::Matchers.generated_description.should == "should have key :a"
77
77
  end
78
-
78
+
79
+ it "should have_some_method" do
80
+ object = Object.new
81
+ def object.has_eyes_closed?; true; end
82
+
83
+ object.should have_eyes_closed
84
+ RSpec::Matchers.generated_description.should == 'should have eyes closed'
85
+ end
86
+
87
+ it "should have_some_method(args*)" do
88
+ object = Object.new
89
+ def object.has_taste_for?(*args); true; end
90
+
91
+ object.should have_taste_for("wine", "cheese")
92
+ RSpec::Matchers.generated_description.should == 'should have taste for "wine", "cheese"'
93
+ end
94
+
79
95
  it "should have n items" do
80
96
  team.should have(3).players
81
97
  RSpec::Matchers.generated_description.should == "should have 3 players"
82
98
  end
83
-
99
+
84
100
  it "should have at least n items" do
85
101
  team.should have_at_least(2).players
86
102
  RSpec::Matchers.generated_description.should == "should have at least 2 players"
87
103
  end
88
-
104
+
89
105
  it "should have at most n items" do
90
106
  team.should have_at_most(4).players
91
107
  RSpec::Matchers.generated_description.should == "should have at most 4 players"
92
108
  end
93
-
109
+
94
110
  it "should include" do
95
111
  [1,2,3].should include(3)
96
112
  RSpec::Matchers.generated_description.should == "should include 3"
@@ -100,42 +116,42 @@ describe "Matchers should be able to generate their own descriptions" do
100
116
  [1,2,3].should =~ [1,2,3]
101
117
  RSpec::Matchers.generated_description.should == "should contain exactly 1, 2 and 3"
102
118
  end
103
-
119
+
104
120
  it "should match" do
105
121
  "this string".should match(/this string/)
106
122
  RSpec::Matchers.generated_description.should == "should match /this string/"
107
123
  end
108
-
124
+
109
125
  it "should raise_error" do
110
126
  lambda { raise }.should raise_error
111
127
  RSpec::Matchers.generated_description.should == "should raise Exception"
112
128
  end
113
-
129
+
114
130
  it "should raise_error with type" do
115
131
  lambda { raise }.should raise_error(RuntimeError)
116
132
  RSpec::Matchers.generated_description.should == "should raise RuntimeError"
117
133
  end
118
-
134
+
119
135
  it "should raise_error with type and message" do
120
136
  lambda { raise "there was an error" }.should raise_error(RuntimeError, "there was an error")
121
137
  RSpec::Matchers.generated_description.should == "should raise RuntimeError with \"there was an error\""
122
138
  end
123
-
139
+
124
140
  it "should respond_to" do
125
141
  [].should respond_to(:insert)
126
142
  RSpec::Matchers.generated_description.should == "should respond to #insert"
127
143
  end
128
-
144
+
129
145
  it "should throw symbol" do
130
146
  lambda { throw :what_a_mess }.should throw_symbol
131
147
  RSpec::Matchers.generated_description.should == "should throw a Symbol"
132
148
  end
133
-
149
+
134
150
  it "should throw symbol (with named symbol)" do
135
151
  lambda { throw :what_a_mess }.should throw_symbol(:what_a_mess)
136
152
  RSpec::Matchers.generated_description.should == "should throw :what_a_mess"
137
153
  end
138
-
154
+
139
155
  def team
140
156
  Class.new do
141
157
  def players
@@ -152,7 +168,7 @@ describe "a Matcher with no description" do
152
168
  def failure_message; ""; end
153
169
  end.new
154
170
  end
155
-
171
+
156
172
  it "provides a helpful message when used in a string-less example block" do
157
173
  5.should matcher
158
174
  RSpec::Matchers.generated_description.should =~ /When you call.*description method/m
@@ -1,65 +1,104 @@
1
1
  require 'spec_helper'
2
2
 
3
- class Substance
4
- def initialize exists, description
5
- @exists = exists
6
- @description = description
7
- end
8
- def exist?(arg=nil)
9
- @exists
10
- end
11
- def inspect
12
- @description
13
- end
14
- end
15
-
16
- class SubstanceTester
17
- include RSpec::Matchers
18
- def initialize substance
19
- @substance = substance
20
- end
21
- def should_exist
22
- @substance.should exist
23
- end
24
- end
3
+ describe "exist matcher" do
4
+ context "when the object does not respond to #exist? or #exists?" do
5
+ subject { mock }
25
6
 
26
- describe "should exist" do
27
-
28
- before(:each) do
29
- @real = Substance.new true, 'something real'
30
- @imaginary = Substance.new false, 'something imaginary'
7
+ [:should, :should_not].each do |should_method|
8
+ describe "#{should_method} exist" do
9
+ it "raises an error" do
10
+ expect {
11
+ subject.send(should_method, exist)
12
+ }.to raise_error(NoMethodError)
13
+ end
14
+ end
15
+ end
31
16
  end
32
17
 
33
- describe "within an example group" do
34
-
35
- it "passes if target exists" do
36
- @real.should exist
37
- end
38
-
39
- it "passes if target exists with args" do
40
- @real.should exist('this arg')
41
- end
42
-
43
- it "fails if target does not exist" do
44
- lambda { @imaginary.should exist }.should fail
45
- end
46
-
47
- it "describes itself" do
48
- exist.description.should == "exist"
49
- end
50
-
51
- it "passes should_not exist if target doesn't exist" do
52
- lambda { @real.should_not exist }.should fail
18
+ [:exist?, :exists?].each do |predicate|
19
+ context "when the object responds to ##{predicate}" do
20
+ describe "should exist" do
21
+ it "passes if #{predicate}" do
22
+ mock(predicate => true).should exist
23
+ end
24
+
25
+ it "fails if not #{predicate}" do
26
+ expect {
27
+ mock(predicate => false).should exist
28
+ }.to fail_with(/expected .* to exist/)
29
+ end
30
+ end
31
+
32
+ describe "should not exist" do
33
+ it "passes if not #{predicate}" do
34
+ mock(predicate => false).should_not exist
35
+ end
36
+
37
+ it "fails if #{predicate}" do
38
+ expect {
39
+ mock(predicate => true).should_not exist
40
+ }.to fail_with(/expected .* not to exist/)
41
+ end
42
+ end
53
43
  end
54
44
  end
55
45
 
56
- describe "outside of an example group" do
46
+ context "when the object responds to #exist? and #exists?" do
47
+ context "when they both return falsey values" do
48
+ subject { mock(:exist? => false, :exists? => nil) }
49
+
50
+ describe "should_not exist" do
51
+ it "passes" do
52
+ subject.should_not exist
53
+ end
54
+ end
55
+
56
+ describe "should exist" do
57
+ it "fails" do
58
+ expect {
59
+ subject.should exist
60
+ }.to fail_with(/expected .* to exist/)
61
+ end
62
+ end
63
+ end
64
+
65
+ context "when they both return truthy values" do
66
+ subject { mock(:exist? => true, :exists? => "something true") }
67
+
68
+ describe "should_not exist" do
69
+ it "fails" do
70
+ expect {
71
+ subject.should_not exist
72
+ }.to fail_with(/expected .* not to exist/)
73
+ end
74
+ end
57
75
 
58
- it "passes if target exists" do
59
- real_tester = SubstanceTester.new @real
60
- real_tester.should_exist
76
+ describe "should exist" do
77
+ it "passes" do
78
+ subject.should exist
79
+ end
80
+ end
61
81
  end
62
82
 
83
+ context "when they return values with different truthiness" do
84
+ subject { mock(:exist? => true, :exists? => false) }
85
+
86
+ [:should, :should_not].each do |should_method|
87
+ describe "#{should_method} exist" do
88
+ it "raises an error" do
89
+ expect {
90
+ subject.send(should_method, exist)
91
+ }.to raise_error(/#exist\? and #exists\? returned different values/)
92
+ end
93
+ end
94
+ end
95
+ end
63
96
  end
64
97
 
98
+ it 'passes any provided arguments to the call to #exist?' do
99
+ object = mock
100
+ object.should_receive(:exist?).with(:foo, :bar) { true }
101
+
102
+ object.should exist(:foo, :bar)
103
+ end
65
104
  end
@@ -26,7 +26,7 @@ describe "should have_sym(*args)" do
26
26
  Object.new.should have_key(:a)
27
27
  }.should raise_error(NoMethodError)
28
28
  end
29
-
29
+
30
30
  it "reraises an exception thrown in #has_sym?(*args)" do
31
31
  o = Object.new
32
32
  def o.has_sym?(*args)
@@ -60,7 +60,7 @@ describe "should_not have_sym(*args)" do
60
60
  Object.new.should have_key(:a)
61
61
  }.should raise_error(NoMethodError)
62
62
  end
63
-
63
+
64
64
  it "reraises an exception thrown in #has_sym?(*args)" do
65
65
  o = Object.new
66
66
  def o.has_sym?(*args)