assert 2.16.5 → 2.18.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -7
  2. data/Gemfile +3 -1
  3. data/README.md +79 -54
  4. data/assert.gemspec +6 -5
  5. data/bin/assert +4 -4
  6. data/lib/assert.rb +8 -18
  7. data/lib/assert/actual_value.rb +127 -0
  8. data/lib/assert/assert_runner.rb +7 -10
  9. data/lib/assert/assertions.rb +15 -28
  10. data/lib/assert/cli.rb +41 -57
  11. data/lib/assert/config.rb +8 -12
  12. data/lib/assert/config_helpers.rb +6 -10
  13. data/lib/assert/context.rb +30 -24
  14. data/lib/assert/context/let_dsl.rb +13 -0
  15. data/lib/assert/context/method_missing.rb +19 -0
  16. data/lib/assert/context/setup_dsl.rb +0 -4
  17. data/lib/assert/context/subject_dsl.rb +0 -4
  18. data/lib/assert/context/suite_dsl.rb +0 -4
  19. data/lib/assert/context/test_dsl.rb +5 -9
  20. data/lib/assert/context_info.rb +2 -6
  21. data/lib/assert/default_runner.rb +1 -5
  22. data/lib/assert/default_suite.rb +1 -6
  23. data/lib/assert/default_view.rb +8 -12
  24. data/lib/assert/factory.rb +1 -4
  25. data/lib/assert/file_line.rb +0 -4
  26. data/lib/assert/macro.rb +1 -4
  27. data/lib/assert/macros/methods.rb +5 -11
  28. data/lib/assert/result.rb +19 -34
  29. data/lib/assert/runner.rb +12 -11
  30. data/lib/assert/stub.rb +16 -2
  31. data/lib/assert/suite.rb +3 -7
  32. data/lib/assert/test.rb +13 -18
  33. data/lib/assert/utils.rb +8 -12
  34. data/lib/assert/version.rb +1 -1
  35. data/lib/assert/view.rb +18 -21
  36. data/lib/assert/view_helpers.rb +6 -17
  37. data/log/{.gitkeep → .keep} +0 -0
  38. data/test/helper.rb +26 -41
  39. data/test/support/factory.rb +20 -6
  40. data/test/support/inherited_stuff.rb +0 -2
  41. data/test/system/stub_tests.rb +350 -354
  42. data/test/system/test_tests.rb +119 -133
  43. data/test/unit/actual_value_tests.rb +335 -0
  44. data/test/unit/assert_tests.rb +125 -52
  45. data/test/unit/assertions/assert_block_tests.rb +34 -37
  46. data/test/unit/assertions/assert_empty_tests.rb +38 -38
  47. data/test/unit/assertions/assert_equal_tests.rb +84 -86
  48. data/test/unit/assertions/assert_file_exists_tests.rb +37 -39
  49. data/test/unit/assertions/assert_includes_tests.rb +45 -46
  50. data/test/unit/assertions/assert_instance_of_tests.rb +39 -40
  51. data/test/unit/assertions/assert_kind_of_tests.rb +39 -40
  52. data/test/unit/assertions/assert_match_tests.rb +39 -40
  53. data/test/unit/assertions/assert_nil_tests.rb +35 -38
  54. data/test/unit/assertions/assert_raises_tests.rb +58 -62
  55. data/test/unit/assertions/assert_respond_to_tests.rb +41 -42
  56. data/test/unit/assertions/assert_same_tests.rb +94 -90
  57. data/test/unit/assertions/assert_true_false_tests.rb +67 -69
  58. data/test/unit/assertions_tests.rb +17 -19
  59. data/test/unit/config_helpers_tests.rb +41 -43
  60. data/test/unit/config_tests.rb +42 -46
  61. data/test/unit/context/let_dsl_tests.rb +10 -0
  62. data/test/unit/context/setup_dsl_tests.rb +72 -91
  63. data/test/unit/context/subject_dsl_tests.rb +18 -51
  64. data/test/unit/context/suite_dsl_tests.rb +19 -23
  65. data/test/unit/context/test_dsl_tests.rb +52 -59
  66. data/test/unit/context_info_tests.rb +19 -21
  67. data/test/unit/context_tests.rb +175 -178
  68. data/test/unit/default_runner_tests.rb +4 -10
  69. data/test/unit/default_suite_tests.rb +54 -59
  70. data/test/unit/factory_tests.rb +6 -9
  71. data/test/unit/file_line_tests.rb +34 -40
  72. data/test/unit/macro_tests.rb +11 -20
  73. data/test/unit/result_tests.rb +156 -182
  74. data/test/unit/runner_tests.rb +72 -79
  75. data/test/unit/suite_tests.rb +62 -63
  76. data/test/unit/test_tests.rb +143 -147
  77. data/test/unit/utils_tests.rb +49 -62
  78. data/test/unit/view_helpers_tests.rb +67 -70
  79. data/test/unit/view_tests.rb +26 -32
  80. metadata +54 -47
  81. data/.assert.rb +0 -3
  82. data/.gitignore +0 -19
@@ -1,8 +1,8 @@
1
- require 'assert/config'
2
- require 'assert/default_suite'
3
- require 'assert/factory'
4
- require 'assert/result'
5
- require 'assert/test'
1
+ require "assert/config"
2
+ require "assert/default_suite"
3
+ require "assert/factory"
4
+ require "assert/result"
5
+ require "assert/test"
6
6
 
7
7
  module Factory
8
8
  extend Assert::Factory
@@ -35,7 +35,7 @@ module Factory
35
35
  config, context_info, name = [
36
36
  args.last.kind_of?(Assert::Config) ? args.pop : self.modes_off_config,
37
37
  args.last.kind_of?(Assert::ContextInfo) ? args.pop : self.context_info,
38
- args.last.kind_of?(::String) ? args.pop : 'a test'
38
+ args.last.kind_of?(::String) ? args.pop : "a test"
39
39
  ]
40
40
  Assert::Test.for_block(name, context_info, config, &block)
41
41
  end
@@ -86,4 +86,18 @@ module Factory
86
86
  end
87
87
  end
88
88
 
89
+ def self.modes_off_context(&result_block)
90
+ test = Factory.test
91
+ Factory.modes_off_context_class.new(
92
+ test,
93
+ test.config,
94
+ result_block || proc { |r| }
95
+ )
96
+ end
97
+
98
+ def self.backtrace
99
+ assert_lib_path =
100
+ File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
101
+ (Factory.integer(3).times.map{ Factory.string } + [assert_lib_path]).shuffle
102
+ end
89
103
  end
@@ -24,7 +24,6 @@ class SuperStuff
24
24
  def test_repeated
25
25
  "repeated test from super"
26
26
  end
27
-
28
27
  end
29
28
 
30
29
  class SubStuff < SuperStuff
@@ -45,5 +44,4 @@ class SubStuff < SuperStuff
45
44
  def test_repeated
46
45
  "repeated test from sub"
47
46
  end
48
-
49
47
  end
@@ -1,700 +1,702 @@
1
- require 'assert'
2
- require 'assert/stub'
1
+ require "assert"
2
+ require "assert/stub"
3
3
 
4
4
  class Assert::Stub
5
-
6
5
  class SystemTests < Assert::Context
7
6
  desc "Assert::Stub"
8
-
9
7
  end
10
8
 
11
9
  class InstanceTests < SystemTests
12
10
  desc "for instance methods"
11
+ subject { instance1 }
12
+
13
13
  setup do
14
- @instance = TestClass.new
15
- Assert.stub(@instance, :noargs){ 'default' }
16
- Assert.stub(@instance, :noargs).with{ 'none' }
14
+ Assert.stub(instance1, :noargs){ "default" }
15
+ Assert.stub(instance1, :noargs).with{ "none" }
17
16
 
18
- Assert.stub(@instance, :withargs){ 'default' }
19
- Assert.stub(@instance, :withargs).with(1){ 'one' }
17
+ Assert.stub(instance1, :withargs){ "default" }
18
+ Assert.stub(instance1, :withargs).with(1){ "one" }
20
19
 
21
- Assert.stub(@instance, :anyargs){ 'default' }
22
- Assert.stub(@instance, :anyargs).with(1, 2){ 'one-two' }
20
+ Assert.stub(instance1, :anyargs){ "default" }
21
+ Assert.stub(instance1, :anyargs).with(1, 2){ "one-two" }
23
22
 
24
- Assert.stub(@instance, :minargs){ 'default' }
25
- Assert.stub(@instance, :minargs).with(1, 2){ 'one-two' }
26
- Assert.stub(@instance, :minargs).with(1, 2, 3){ 'one-two-three' }
23
+ Assert.stub(instance1, :minargs){ "default" }
24
+ Assert.stub(instance1, :minargs).with(1, 2){ "one-two" }
25
+ Assert.stub(instance1, :minargs).with(1, 2, 3){ "one-two-three" }
27
26
 
28
- Assert.stub(@instance, :withblock){ 'default' }
27
+ Assert.stub(instance1, :withblock){ "default" }
29
28
  end
30
- subject{ @instance }
29
+
30
+ let(:instance1) { TestClass.new }
31
31
 
32
32
  should "allow stubbing a method that doesn't take args" do
33
- assert_equal 'none', subject.noargs
33
+ assert_that(subject.noargs).equals("none")
34
34
  end
35
35
 
36
36
  should "allow stubbing a method that takes args" do
37
- assert_equal 'one', subject.withargs(1)
38
- assert_equal 'default', subject.withargs(2)
37
+ assert_that(subject.withargs(2)).equals("default")
39
38
  end
40
39
 
41
40
  should "allow stubbing a method that takes any args" do
42
- assert_equal 'default', subject.anyargs
43
- assert_equal 'default', subject.anyargs(1)
44
- assert_equal 'one-two', subject.anyargs(1, 2)
41
+ assert_that(subject.anyargs).equals("default")
42
+ assert_that(subject.anyargs(1)).equals("default")
43
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
45
44
  end
46
45
 
47
46
  should "allow stubbing a method that takes a minimum number of args" do
48
- assert_equal 'one-two', subject.minargs(1, 2)
49
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
50
- assert_equal 'default', subject.minargs(1, 2, 4)
51
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
47
+ assert_that(subject.minargs(1, 2)).equals("one-two")
48
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
49
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
50
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
52
51
  end
53
52
 
54
53
  should "allow stubbing a method that takes a block" do
55
- assert_equal 'default', subject.withblock
56
- assert_equal 'default', subject.withblock{ 'my-block' }
54
+ assert_that(subject.withblock).equals("default")
55
+ assert_that(subject.withblock{ "my-block" }).equals("default")
57
56
  end
58
57
 
59
58
  should "not allow stubbing methods with invalid arity" do
60
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
59
+ assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
61
60
 
62
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
63
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
61
+ assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
62
+ assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
64
63
 
65
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
66
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
64
+ assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
65
+ assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
67
66
 
68
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
67
+ assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
69
68
  end
70
69
 
71
70
  should "not allow calling methods with invalid arity" do
72
- assert_raises{ subject.noargs(1) }
71
+ assert_that(-> { subject.noargs(1) }).raises
73
72
 
74
- assert_raises{ subject.withargs }
75
- assert_raises{ subject.withargs(1, 2) }
73
+ assert_that(-> { subject.withargs }).raises
74
+ assert_that(-> { subject.withargs(1, 2) }).raises
76
75
 
77
- assert_raises{ subject.minargs }
78
- assert_raises{ subject.minargs(1) }
76
+ assert_that(-> { subject.minargs }).raises
77
+ assert_that(-> { subject.minargs(1) }).raises
79
78
 
80
- assert_raises{ subject.withblock(1) }
79
+ assert_that(-> { subject.withblock(1) }).raises
81
80
  end
82
-
83
81
  end
84
82
 
85
83
  class ClassTests < SystemTests
86
84
  desc "for singleton methods on a class"
85
+ subject { class1 }
86
+
87
87
  setup do
88
- @class = TestClass
89
- Assert.stub(@class, :noargs){ 'default' }
90
- Assert.stub(@class, :noargs).with{ 'none' }
88
+ Assert.stub(class1, :noargs){ "default" }
89
+ Assert.stub(class1, :noargs).with{ "none" }
91
90
 
92
- Assert.stub(@class, :withargs){ 'default' }
93
- Assert.stub(@class, :withargs).with(1){ 'one' }
91
+ Assert.stub(class1, :withargs){ "default" }
92
+ Assert.stub(class1, :withargs).with(1){ "one" }
94
93
 
95
- Assert.stub(@class, :anyargs){ 'default' }
96
- Assert.stub(@class, :anyargs).with(1, 2){ 'one-two' }
94
+ Assert.stub(class1, :anyargs){ "default" }
95
+ Assert.stub(class1, :anyargs).with(1, 2){ "one-two" }
97
96
 
98
- Assert.stub(@class, :minargs){ 'default' }
99
- Assert.stub(@class, :minargs).with(1, 2){ 'one-two' }
100
- Assert.stub(@class, :minargs).with(1, 2, 3){ 'one-two-three' }
97
+ Assert.stub(class1, :minargs){ "default" }
98
+ Assert.stub(class1, :minargs).with(1, 2){ "one-two" }
99
+ Assert.stub(class1, :minargs).with(1, 2, 3){ "one-two-three" }
101
100
 
102
- Assert.stub(@class, :withblock){ 'default' }
101
+ Assert.stub(class1, :withblock){ "default" }
103
102
  end
104
- subject{ @class }
103
+
104
+ let(:class1) { TestClass }
105
105
 
106
106
  should "allow stubbing a method that doesn't take args" do
107
- assert_equal 'none', subject.noargs
107
+ assert_that(subject.noargs).equals("none")
108
108
  end
109
109
 
110
110
  should "allow stubbing a method that takes args" do
111
- assert_equal 'one', subject.withargs(1)
112
- assert_equal 'default', subject.withargs(2)
111
+ assert_that(subject.withargs(1)).equals("one")
112
+ assert_that(subject.withargs(2)).equals("default")
113
113
  end
114
114
 
115
115
  should "allow stubbing a method that takes any args" do
116
- assert_equal 'default', subject.anyargs
117
- assert_equal 'default', subject.anyargs(1)
118
- assert_equal 'one-two', subject.anyargs(1, 2)
116
+ assert_that(subject.anyargs).equals("default")
117
+ assert_that(subject.anyargs(1)).equals("default")
118
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
119
119
  end
120
120
 
121
121
  should "allow stubbing a method that takes a minimum number of args" do
122
- assert_equal 'one-two', subject.minargs(1, 2)
123
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
124
- assert_equal 'default', subject.minargs(1, 2, 4)
125
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
122
+ assert_that(subject.minargs(1, 2)).equals("one-two")
123
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
124
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
125
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
126
126
  end
127
127
 
128
128
  should "allow stubbing a method that takes a block" do
129
- assert_equal 'default', subject.withblock
130
- assert_equal 'default', subject.withblock{ 'my-block' }
129
+ assert_that(subject.withblock).equals("default")
130
+ assert_that(subject.withblock{ "my-block" }).equals("default")
131
131
  end
132
132
 
133
133
  should "not allow stubbing methods with invalid arity" do
134
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
134
+ assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
135
135
 
136
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
137
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
136
+ assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
137
+ assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
138
138
 
139
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
140
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
139
+ assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
140
+ assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
141
141
 
142
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
142
+ assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
143
143
  end
144
144
 
145
145
  should "not allow calling methods with invalid arity" do
146
- assert_raises{ subject.noargs(1) }
146
+ assert_that(-> { subject.noargs(1) }).raises
147
147
 
148
- assert_raises{ subject.withargs }
149
- assert_raises{ subject.withargs(1, 2) }
148
+ assert_that(-> { subject.withargs }).raises
149
+ assert_that(-> { subject.withargs(1, 2) }).raises
150
150
 
151
- assert_raises{ subject.minargs }
152
- assert_raises{ subject.minargs(1) }
151
+ assert_that(-> { subject.minargs }).raises
152
+ assert_that(-> { subject.minargs(1) }).raises
153
153
 
154
- assert_raises{ subject.withblock(1) }
154
+ assert_that(-> { subject.withblock(1) }).raises
155
155
  end
156
-
157
156
  end
158
157
 
159
158
  class ModuleTests < SystemTests
160
159
  desc "for singleton methods on a module"
160
+ subject { module1 }
161
+
161
162
  setup do
162
- @module = TestModule
163
- Assert.stub(@module, :noargs){ 'default' }
164
- Assert.stub(@module, :noargs).with{ 'none' }
163
+ Assert.stub(module1, :noargs){ "default" }
164
+ Assert.stub(module1, :noargs).with{ "none" }
165
165
 
166
- Assert.stub(@module, :withargs){ 'default' }
167
- Assert.stub(@module, :withargs).with(1){ 'one' }
166
+ Assert.stub(module1, :withargs){ "default" }
167
+ Assert.stub(module1, :withargs).with(1){ "one" }
168
168
 
169
- Assert.stub(@module, :anyargs){ 'default' }
170
- Assert.stub(@module, :anyargs).with(1, 2){ 'one-two' }
169
+ Assert.stub(module1, :anyargs){ "default" }
170
+ Assert.stub(module1, :anyargs).with(1, 2){ "one-two" }
171
171
 
172
- Assert.stub(@module, :minargs){ 'default' }
173
- Assert.stub(@module, :minargs).with(1, 2){ 'one-two' }
174
- Assert.stub(@module, :minargs).with(1, 2, 3){ 'one-two-three' }
172
+ Assert.stub(module1, :minargs){ "default" }
173
+ Assert.stub(module1, :minargs).with(1, 2){ "one-two" }
174
+ Assert.stub(module1, :minargs).with(1, 2, 3){ "one-two-three" }
175
175
 
176
- Assert.stub(@module, :withblock){ 'default' }
176
+ Assert.stub(module1, :withblock){ "default" }
177
177
  end
178
- subject{ @module }
178
+
179
+ let(:module1) { TestModule }
179
180
 
180
181
  should "allow stubbing a method that doesn't take args" do
181
- assert_equal 'none', subject.noargs
182
+ assert_that(subject.noargs).equals("none")
182
183
  end
183
184
 
184
185
  should "allow stubbing a method that takes args" do
185
- assert_equal 'one', subject.withargs(1)
186
- assert_equal 'default', subject.withargs(2)
186
+ assert_that(subject.withargs(1)).equals("one")
187
+ assert_that(subject.withargs(2)).equals("default")
187
188
  end
188
189
 
189
190
  should "allow stubbing a method that takes any args" do
190
- assert_equal 'default', subject.anyargs
191
- assert_equal 'default', subject.anyargs(1)
192
- assert_equal 'one-two', subject.anyargs(1, 2)
191
+ assert_that(subject.anyargs).equals("default")
192
+ assert_that(subject.anyargs(1)).equals("default")
193
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
193
194
  end
194
195
 
195
196
  should "allow stubbing a method that takes a minimum number of args" do
196
- assert_equal 'one-two', subject.minargs(1, 2)
197
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
198
- assert_equal 'default', subject.minargs(1, 2, 4)
199
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
197
+ assert_that(subject.minargs(1, 2)).equals("one-two")
198
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
199
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
200
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
200
201
  end
201
202
 
202
203
  should "allow stubbing a method that takes a block" do
203
- assert_equal 'default', subject.withblock
204
- assert_equal 'default', subject.withblock{ 'my-block' }
204
+ assert_that(subject.withblock).equals("default")
205
+ assert_that(subject.withblock{ "my-block" }).equals("default")
205
206
  end
206
207
 
207
208
  should "not allow stubbing methods with invalid arity" do
208
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
209
+ assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
209
210
 
210
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
211
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
211
+ assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
212
+ assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
212
213
 
213
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
214
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
214
+ assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
215
+ assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
215
216
 
216
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
217
+ assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
217
218
  end
218
219
 
219
220
  should "not allow calling methods with invalid arity" do
220
- assert_raises{ subject.noargs(1) }
221
+ assert_that(-> { subject.noargs(1) }).raises
221
222
 
222
- assert_raises{ subject.withargs }
223
- assert_raises{ subject.withargs(1, 2) }
223
+ assert_that(-> { subject.withargs }).raises
224
+ assert_that(-> { subject.withargs(1, 2) }).raises
224
225
 
225
- assert_raises{ subject.minargs }
226
- assert_raises{ subject.minargs(1) }
226
+ assert_that(-> { subject.minargs }).raises
227
+ assert_that(-> { subject.minargs(1) }).raises
227
228
 
228
- assert_raises{ subject.withblock(1) }
229
+ assert_that(-> { subject.withblock(1) }).raises
229
230
  end
230
-
231
231
  end
232
232
 
233
233
  class ExtendedTests < SystemTests
234
234
  desc "for extended methods"
235
+ subject { class1 }
236
+
235
237
  setup do
236
- @class = Class.new{ extend TestMixin }
237
- Assert.stub(@class, :noargs){ 'default' }
238
- Assert.stub(@class, :noargs).with{ 'none' }
238
+ Assert.stub(class1, :noargs){ "default" }
239
+ Assert.stub(class1, :noargs).with{ "none" }
239
240
 
240
- Assert.stub(@class, :withargs){ 'default' }
241
- Assert.stub(@class, :withargs).with(1){ 'one' }
241
+ Assert.stub(class1, :withargs){ "default" }
242
+ Assert.stub(class1, :withargs).with(1){ "one" }
242
243
 
243
- Assert.stub(@class, :anyargs){ 'default' }
244
- Assert.stub(@class, :anyargs).with(1, 2){ 'one-two' }
244
+ Assert.stub(class1, :anyargs){ "default" }
245
+ Assert.stub(class1, :anyargs).with(1, 2){ "one-two" }
245
246
 
246
- Assert.stub(@class, :minargs){ 'default' }
247
- Assert.stub(@class, :minargs).with(1, 2){ 'one-two' }
248
- Assert.stub(@class, :minargs).with(1, 2, 3){ 'one-two-three' }
247
+ Assert.stub(class1, :minargs){ "default" }
248
+ Assert.stub(class1, :minargs).with(1, 2){ "one-two" }
249
+ Assert.stub(class1, :minargs).with(1, 2, 3){ "one-two-three" }
249
250
 
250
- Assert.stub(@class, :withblock){ 'default' }
251
+ Assert.stub(class1, :withblock){ "default" }
251
252
  end
252
- subject{ @class }
253
+
254
+ let(:class1) { Class.new{ extend TestMixin } }
253
255
 
254
256
  should "allow stubbing a method that doesn't take args" do
255
- assert_equal 'none', subject.noargs
257
+ assert_that(subject.noargs).equals("none")
256
258
  end
257
259
 
258
260
  should "allow stubbing a method that takes args" do
259
- assert_equal 'one', subject.withargs(1)
260
- assert_equal 'default', subject.withargs(2)
261
+ assert_that(subject.withargs(1)).equals("one")
262
+ assert_that(subject.withargs(2)).equals("default")
261
263
  end
262
264
 
263
265
  should "allow stubbing a method that takes any args" do
264
- assert_equal 'default', subject.anyargs
265
- assert_equal 'default', subject.anyargs(1)
266
- assert_equal 'one-two', subject.anyargs(1, 2)
266
+ assert_that(subject.anyargs).equals("default")
267
+ assert_that(subject.anyargs(1)).equals("default")
268
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
267
269
  end
268
270
 
269
271
  should "allow stubbing a method that takes a minimum number of args" do
270
- assert_equal 'one-two', subject.minargs(1, 2)
271
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
272
- assert_equal 'default', subject.minargs(1, 2, 4)
273
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
272
+ assert_that(subject.minargs(1, 2)).equals("one-two")
273
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
274
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
275
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
274
276
  end
275
277
 
276
278
  should "allow stubbing a method that takes a block" do
277
- assert_equal 'default', subject.withblock
278
- assert_equal 'default', subject.withblock{ 'my-block' }
279
+ assert_that(subject.withblock).equals("default")
280
+ assert_that(subject.withblock{ "my-block" }).equals("default")
279
281
  end
280
282
 
281
283
  should "not allow stubbing methods with invalid arity" do
282
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
284
+ assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
283
285
 
284
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
285
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
286
+ assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
287
+ assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
286
288
 
287
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
288
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
289
+ assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
290
+ assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
289
291
 
290
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
292
+ assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
291
293
  end
292
294
 
293
295
  should "not allow calling methods with invalid arity" do
294
- assert_raises{ subject.noargs(1) }
296
+ assert_that(-> { subject.noargs(1) }).raises
295
297
 
296
- assert_raises{ subject.withargs }
297
- assert_raises{ subject.withargs(1, 2) }
298
+ assert_that(-> { subject.withargs }).raises
299
+ assert_that(-> { subject.withargs(1, 2) }).raises
298
300
 
299
- assert_raises{ subject.minargs }
300
- assert_raises{ subject.minargs(1) }
301
+ assert_that(-> { subject.minargs }).raises
302
+ assert_that(-> { subject.minargs(1) }).raises
301
303
 
302
- assert_raises{ subject.withblock(1) }
304
+ assert_that(-> { subject.withblock(1) }).raises
303
305
  end
304
-
305
306
  end
306
307
 
307
308
  class IncludedTests < SystemTests
308
309
  desc "for an included method"
310
+ subject { instance1 }
311
+
309
312
  setup do
310
- @class = Class.new{ include TestMixin }
311
- @instance = @class.new
312
- Assert.stub(@instance, :noargs){ 'default' }
313
- Assert.stub(@instance, :noargs).with{ 'none' }
313
+ Assert.stub(instance1, :noargs){ "default" }
314
+ Assert.stub(instance1, :noargs).with{ "none" }
314
315
 
315
- Assert.stub(@instance, :withargs){ 'default' }
316
- Assert.stub(@instance, :withargs).with(1){ 'one' }
316
+ Assert.stub(instance1, :withargs){ "default" }
317
+ Assert.stub(instance1, :withargs).with(1){ "one" }
317
318
 
318
- Assert.stub(@instance, :anyargs){ 'default' }
319
- Assert.stub(@instance, :anyargs).with(1, 2){ 'one-two' }
319
+ Assert.stub(instance1, :anyargs){ "default" }
320
+ Assert.stub(instance1, :anyargs).with(1, 2){ "one-two" }
320
321
 
321
- Assert.stub(@instance, :minargs){ 'default' }
322
- Assert.stub(@instance, :minargs).with(1, 2){ 'one-two' }
323
- Assert.stub(@instance, :minargs).with(1, 2, 3){ 'one-two-three' }
322
+ Assert.stub(instance1, :minargs){ "default" }
323
+ Assert.stub(instance1, :minargs).with(1, 2){ "one-two" }
324
+ Assert.stub(instance1, :minargs).with(1, 2, 3){ "one-two-three" }
324
325
 
325
- Assert.stub(@instance, :withblock){ 'default' }
326
+ Assert.stub(instance1, :withblock){ "default" }
326
327
  end
327
- subject{ @instance }
328
+
329
+ let(:instance1) { Class.new { include TestMixin }.new }
328
330
 
329
331
  should "allow stubbing a method that doesn't take args" do
330
- assert_equal 'none', subject.noargs
332
+ assert_that(subject.noargs).equals("none")
331
333
  end
332
334
 
333
335
  should "allow stubbing a method that takes args" do
334
- assert_equal 'one', subject.withargs(1)
335
- assert_equal 'default', subject.withargs(2)
336
+ assert_that(subject.withargs(1)).equals("one")
337
+ assert_that(subject.withargs(2)).equals("default")
336
338
  end
337
339
 
338
340
  should "allow stubbing a method that takes any args" do
339
- assert_equal 'default', subject.anyargs
340
- assert_equal 'default', subject.anyargs(1)
341
- assert_equal 'one-two', subject.anyargs(1, 2)
341
+ assert_that(subject.anyargs).equals("default")
342
+ assert_that(subject.anyargs(1)).equals("default")
343
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
342
344
  end
343
345
 
344
346
  should "allow stubbing a method that takes a minimum number of args" do
345
- assert_equal 'one-two', subject.minargs(1, 2)
346
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
347
- assert_equal 'default', subject.minargs(1, 2, 4)
348
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
347
+ assert_that(subject.minargs(1, 2)).equals("one-two")
348
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
349
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
350
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
349
351
  end
350
352
 
351
353
  should "allow stubbing a method that takes a block" do
352
- assert_equal 'default', subject.withblock
353
- assert_equal 'default', subject.withblock{ 'my-block' }
354
+ assert_that(subject.withblock).equals("default")
355
+ assert_that(subject.withblock{ "my-block" }).equals("default")
354
356
  end
355
357
 
356
358
  should "not allow stubbing methods with invalid arity" do
357
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
359
+ assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
358
360
 
359
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
360
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
361
+ assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
362
+ assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
361
363
 
362
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
363
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
364
+ assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
365
+ assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
364
366
 
365
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
367
+ assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
366
368
  end
367
369
 
368
370
  should "not allow calling methods with invalid arity" do
369
- assert_raises{ subject.noargs(1) }
371
+ assert_that(-> { subject.noargs(1) }).raises
370
372
 
371
- assert_raises{ subject.withargs }
372
- assert_raises{ subject.withargs(1, 2) }
373
+ assert_that(-> { subject.withargs }).raises
374
+ assert_that(-> { subject.withargs(1, 2) }).raises
373
375
 
374
- assert_raises{ subject.minargs }
375
- assert_raises{ subject.minargs(1) }
376
+ assert_that(-> { subject.minargs }).raises
377
+ assert_that(-> { subject.minargs(1) }).raises
376
378
 
377
- assert_raises{ subject.withblock(1) }
379
+ assert_that(-> { subject.withblock(1) }).raises
378
380
  end
379
-
380
381
  end
381
382
 
382
383
  class InheritedClassTests < SystemTests
383
384
  desc "for an inherited class method"
385
+ subject { class1 }
386
+
384
387
  setup do
385
- @class = Class.new(TestClass)
386
- Assert.stub(@class, :noargs){ 'default' }
387
- Assert.stub(@class, :noargs).with{ 'none' }
388
+ Assert.stub(class1, :noargs){ "default" }
389
+ Assert.stub(class1, :noargs).with{ "none" }
388
390
 
389
- Assert.stub(@class, :withargs){ 'default' }
390
- Assert.stub(@class, :withargs).with(1){ 'one' }
391
+ Assert.stub(class1, :withargs){ "default" }
392
+ Assert.stub(class1, :withargs).with(1){ "one" }
391
393
 
392
- Assert.stub(@class, :anyargs){ 'default' }
393
- Assert.stub(@class, :anyargs).with(1, 2){ 'one-two' }
394
+ Assert.stub(class1, :anyargs){ "default" }
395
+ Assert.stub(class1, :anyargs).with(1, 2){ "one-two" }
394
396
 
395
- Assert.stub(@class, :minargs){ 'default' }
396
- Assert.stub(@class, :minargs).with(1, 2){ 'one-two' }
397
- Assert.stub(@class, :minargs).with(1, 2, 3){ 'one-two-three' }
397
+ Assert.stub(class1, :minargs){ "default" }
398
+ Assert.stub(class1, :minargs).with(1, 2){ "one-two" }
399
+ Assert.stub(class1, :minargs).with(1, 2, 3){ "one-two-three" }
398
400
 
399
- Assert.stub(@class, :withblock){ 'default' }
401
+ Assert.stub(class1, :withblock){ "default" }
400
402
  end
401
- subject{ @class }
403
+
404
+ let(:class1) { Class.new(TestClass) }
402
405
 
403
406
  should "allow stubbing a method that doesn't take args" do
404
- assert_equal 'none', subject.noargs
407
+ assert_that(subject.noargs).equals("none")
405
408
  end
406
409
 
407
410
  should "allow stubbing a method that takes args" do
408
- assert_equal 'one', subject.withargs(1)
409
- assert_equal 'default', subject.withargs(2)
411
+ assert_that(subject.withargs(1)).equals("one")
412
+ assert_that(subject.withargs(2)).equals("default")
410
413
  end
411
414
 
412
415
  should "allow stubbing a method that takes any args" do
413
- assert_equal 'default', subject.anyargs
414
- assert_equal 'default', subject.anyargs(1)
415
- assert_equal 'one-two', subject.anyargs(1, 2)
416
+ assert_that(subject.anyargs).equals("default")
417
+ assert_that(subject.anyargs(1)).equals("default")
418
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
416
419
  end
417
420
 
418
421
  should "allow stubbing a method that takes a minimum number of args" do
419
- assert_equal 'one-two', subject.minargs(1, 2)
420
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
421
- assert_equal 'default', subject.minargs(1, 2, 4)
422
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
422
+ assert_that(subject.minargs(1, 2)).equals("one-two")
423
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
424
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
425
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
423
426
  end
424
427
 
425
428
  should "allow stubbing a method that takes a block" do
426
- assert_equal 'default', subject.withblock
427
- assert_equal 'default', subject.withblock{ 'my-block' }
429
+ assert_that(subject.withblock).equals("default")
430
+ assert_that(subject.withblock{ "my-block" }).equals("default")
428
431
  end
429
432
 
430
433
  should "not allow stubbing methods with invalid arity" do
431
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
434
+ assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
432
435
 
433
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
434
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
436
+ assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
437
+ assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
435
438
 
436
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
437
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
439
+ assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
440
+ assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
438
441
 
439
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
442
+ assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
440
443
  end
441
444
 
442
445
  should "not allow calling methods with invalid arity" do
443
- assert_raises{ subject.noargs(1) }
446
+ assert_that(-> { subject.noargs(1) }).raises
444
447
 
445
- assert_raises{ subject.withargs }
446
- assert_raises{ subject.withargs(1, 2) }
448
+ assert_that(-> { subject.withargs }).raises
449
+ assert_that(-> { subject.withargs(1, 2) }).raises
447
450
 
448
- assert_raises{ subject.minargs }
449
- assert_raises{ subject.minargs(1) }
451
+ assert_that(-> { subject.minargs }).raises
452
+ assert_that(-> { subject.minargs(1) }).raises
450
453
 
451
- assert_raises{ subject.withblock(1) }
454
+ assert_that(-> { subject.withblock(1) }).raises
452
455
  end
453
-
454
456
  end
455
457
 
456
458
  class InheritedInstanceTests < SystemTests
457
459
  desc "for an inherited instance method"
460
+ subject { instance1 }
461
+
458
462
  setup do
459
- @class = Class.new(TestClass)
460
- @instance = @class.new
461
- Assert.stub(@instance, :noargs){ 'default' }
462
- Assert.stub(@instance, :noargs).with{ 'none' }
463
+ Assert.stub(instance1, :noargs){ "default" }
464
+ Assert.stub(instance1, :noargs).with{ "none" }
463
465
 
464
- Assert.stub(@instance, :withargs){ 'default' }
465
- Assert.stub(@instance, :withargs).with(1){ 'one' }
466
+ Assert.stub(instance1, :withargs){ "default" }
467
+ Assert.stub(instance1, :withargs).with(1){ "one" }
466
468
 
467
- Assert.stub(@instance, :anyargs){ 'default' }
468
- Assert.stub(@instance, :anyargs).with(1, 2){ 'one-two' }
469
+ Assert.stub(instance1, :anyargs){ "default" }
470
+ Assert.stub(instance1, :anyargs).with(1, 2){ "one-two" }
469
471
 
470
- Assert.stub(@instance, :minargs){ 'default' }
471
- Assert.stub(@instance, :minargs).with(1, 2){ 'one-two' }
472
- Assert.stub(@instance, :minargs).with(1, 2, 3){ 'one-two-three' }
472
+ Assert.stub(instance1, :minargs){ "default" }
473
+ Assert.stub(instance1, :minargs).with(1, 2){ "one-two" }
474
+ Assert.stub(instance1, :minargs).with(1, 2, 3){ "one-two-three" }
473
475
 
474
- Assert.stub(@instance, :withblock){ 'default' }
476
+ Assert.stub(instance1, :withblock){ "default" }
475
477
  end
476
- subject{ @instance }
478
+
479
+ let(:instance1) { Class.new(TestClass).new }
477
480
 
478
481
  should "allow stubbing a method that doesn't take args" do
479
- assert_equal 'none', subject.noargs
482
+ assert_that(subject.noargs).equals("none")
480
483
  end
481
484
 
482
485
  should "allow stubbing a method that takes args" do
483
- assert_equal 'one', subject.withargs(1)
484
- assert_equal 'default', subject.withargs(2)
486
+ assert_that(subject.withargs(1)).equals("one")
487
+ assert_that(subject.withargs(2)).equals("default")
485
488
  end
486
489
 
487
490
  should "allow stubbing a method that takes any args" do
488
- assert_equal 'default', subject.anyargs
489
- assert_equal 'default', subject.anyargs(1)
490
- assert_equal 'one-two', subject.anyargs(1, 2)
491
+ assert_that(subject.anyargs).equals("default")
492
+ assert_that(subject.anyargs(1)).equals("default")
493
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
491
494
  end
492
495
 
493
496
  should "allow stubbing a method that takes a minimum number of args" do
494
- assert_equal 'one-two', subject.minargs(1, 2)
495
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
496
- assert_equal 'default', subject.minargs(1, 2, 4)
497
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
497
+ assert_that(subject.minargs(1, 2)).equals("one-two")
498
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
499
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
500
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
498
501
  end
499
502
 
500
503
  should "allow stubbing a method that takes a block" do
501
- assert_equal 'default', subject.withblock
502
- assert_equal 'default', subject.withblock{ 'my-block' }
504
+ assert_that(subject.withblock).equals("default")
505
+ assert_that(subject.withblock{ "my-block" }).equals("default")
503
506
  end
504
507
 
505
508
  should "not allow stubbing methods with invalid arity" do
506
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
509
+ assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
507
510
 
508
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
509
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
511
+ assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
512
+ assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
510
513
 
511
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
512
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
514
+ assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
515
+ assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
513
516
 
514
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
517
+ assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
515
518
  end
516
519
 
517
520
  should "not allow calling methods with invalid arity" do
518
- assert_raises{ subject.noargs(1) }
521
+ assert_that(-> { subject.noargs(1) }).raises
519
522
 
520
- assert_raises{ subject.withargs }
521
- assert_raises{ subject.withargs(1, 2) }
523
+ assert_that(-> { subject.withargs }).raises
524
+ assert_that(-> { subject.withargs(1, 2) }).raises
522
525
 
523
- assert_raises{ subject.minargs }
524
- assert_raises{ subject.minargs(1) }
526
+ assert_that(-> { subject.minargs }).raises
527
+ assert_that(-> { subject.minargs(1) }).raises
525
528
 
526
- assert_raises{ subject.withblock(1) }
529
+ assert_that(-> { subject.withblock(1) }).raises
527
530
  end
528
-
529
531
  end
530
532
 
531
533
  class DelegateClassTests < SystemTests
532
534
  desc "a class that delegates another object"
535
+ subject { class1 }
536
+
533
537
  setup do
534
- @class = DelegateClass
535
- Assert.stub(@class, :noargs){ 'default' }
536
- Assert.stub(@class, :noargs).with{ 'none' }
538
+ Assert.stub(class1, :noargs){ "default" }
539
+ Assert.stub(class1, :noargs).with{ "none" }
537
540
 
538
- Assert.stub(@class, :withargs){ 'default' }
539
- Assert.stub(@class, :withargs).with(1){ 'one' }
541
+ Assert.stub(class1, :withargs){ "default" }
542
+ Assert.stub(class1, :withargs).with(1){ "one" }
540
543
 
541
- Assert.stub(@class, :anyargs){ 'default' }
542
- Assert.stub(@class, :anyargs).with(1, 2){ 'one-two' }
544
+ Assert.stub(class1, :anyargs){ "default" }
545
+ Assert.stub(class1, :anyargs).with(1, 2){ "one-two" }
543
546
 
544
- Assert.stub(@class, :minargs){ 'default' }
545
- Assert.stub(@class, :minargs).with(1, 2){ 'one-two' }
546
- Assert.stub(@class, :minargs).with(1, 2, 3){ 'one-two-three' }
547
+ Assert.stub(class1, :minargs){ "default" }
548
+ Assert.stub(class1, :minargs).with(1, 2){ "one-two" }
549
+ Assert.stub(class1, :minargs).with(1, 2, 3){ "one-two-three" }
547
550
 
548
- Assert.stub(@class, :withblock){ 'default' }
551
+ Assert.stub(class1, :withblock){ "default" }
549
552
  end
550
- subject{ @class }
553
+
554
+ let(:class1) { DelegateClass }
551
555
 
552
556
  should "allow stubbing a method that doesn't take args" do
553
- assert_equal 'none', subject.noargs
557
+ assert_that(subject.noargs).equals("none")
554
558
  end
555
559
 
556
560
  should "allow stubbing a method that takes args" do
557
- assert_equal 'one', subject.withargs(1)
558
- assert_equal 'default', subject.withargs(2)
561
+ assert_that(subject.withargs(1)).equals("one")
562
+ assert_that(subject.withargs(2)).equals("default")
559
563
  end
560
564
 
561
565
  should "allow stubbing a method that takes any args" do
562
- assert_equal 'default', subject.anyargs
563
- assert_equal 'default', subject.anyargs(1)
564
- assert_equal 'one-two', subject.anyargs(1, 2)
566
+ assert_that(subject.anyargs).equals("default")
567
+ assert_that(subject.anyargs(1)).equals("default")
568
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
565
569
  end
566
570
 
567
571
  should "allow stubbing a method that takes a minimum number of args" do
568
- assert_equal 'one-two', subject.minargs(1, 2)
569
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
570
- assert_equal 'default', subject.minargs(1, 2, 4)
571
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
572
+ assert_that(subject.minargs(1, 2)).equals("one-two")
573
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
574
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
575
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
572
576
  end
573
577
 
574
578
  should "allow stubbing a method that takes a block" do
575
- assert_equal 'default', subject.withblock
576
- assert_equal 'default', subject.withblock{ 'my-block' }
579
+ assert_that(subject.withblock).equals("default")
580
+ assert_that(subject.withblock{ "my-block" }).equals("default")
577
581
  end
578
582
 
579
583
  should "allow stubbing methods with invalid arity" do
580
- assert_nothing_raised{ Assert.stub(subject, :noargs).with(1){ } }
584
+ assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).does_not_raise
581
585
 
582
- assert_nothing_raised{ Assert.stub(subject, :withargs).with{ } }
583
- assert_nothing_raised{ Assert.stub(subject, :withargs).with(1, 2){ } }
586
+ assert_that(-> { Assert.stub(subject, :withargs).with{ } }).does_not_raise
587
+ assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).does_not_raise
584
588
 
585
- assert_nothing_raised{ Assert.stub(subject, :minargs).with{ } }
586
- assert_nothing_raised{ Assert.stub(subject, :minargs).with(1){ } }
589
+ assert_that(-> { Assert.stub(subject, :minargs).with{ } }).does_not_raise
590
+ assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).does_not_raise
587
591
 
588
- assert_nothing_raised{ Assert.stub(subject, :withblock).with(1){ } }
592
+ assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).does_not_raise
589
593
  end
590
594
 
591
595
  should "allow calling methods with invalid arity" do
592
- assert_nothing_raised{ subject.noargs(1) }
596
+ assert_that(-> { subject.noargs(1) }).does_not_raise
593
597
 
594
- assert_nothing_raised{ subject.withargs }
595
- assert_nothing_raised{ subject.withargs(1, 2) }
598
+ assert_that(-> { subject.withargs }).does_not_raise
599
+ assert_that(-> { subject.withargs(1, 2) }).does_not_raise
596
600
 
597
- assert_nothing_raised{ subject.minargs }
598
- assert_nothing_raised{ subject.minargs(1) }
601
+ assert_that(-> { subject.minargs }).does_not_raise
602
+ assert_that(-> { subject.minargs(1) }).does_not_raise
599
603
 
600
- assert_nothing_raised{ subject.withblock(1) }
604
+ assert_that(-> { subject.withblock(1) }).does_not_raise
601
605
  end
602
-
603
606
  end
604
607
 
605
608
  class DelegateInstanceTests < SystemTests
606
609
  desc "an instance that delegates another object"
610
+ subject { instance1 }
611
+
607
612
  setup do
608
- @instance = DelegateClass.new
609
- Assert.stub(@instance, :noargs){ 'default' }
610
- Assert.stub(@instance, :noargs).with{ 'none' }
613
+ Assert.stub(instance1, :noargs){ "default" }
614
+ Assert.stub(instance1, :noargs).with{ "none" }
611
615
 
612
- Assert.stub(@instance, :withargs){ 'default' }
613
- Assert.stub(@instance, :withargs).with(1){ 'one' }
616
+ Assert.stub(instance1, :withargs){ "default" }
617
+ Assert.stub(instance1, :withargs).with(1){ "one" }
614
618
 
615
- Assert.stub(@instance, :anyargs){ 'default' }
616
- Assert.stub(@instance, :anyargs).with(1, 2){ 'one-two' }
619
+ Assert.stub(instance1, :anyargs){ "default" }
620
+ Assert.stub(instance1, :anyargs).with(1, 2){ "one-two" }
617
621
 
618
- Assert.stub(@instance, :minargs){ 'default' }
619
- Assert.stub(@instance, :minargs).with(1, 2){ 'one-two' }
620
- Assert.stub(@instance, :minargs).with(1, 2, 3){ 'one-two-three' }
622
+ Assert.stub(instance1, :minargs){ "default" }
623
+ Assert.stub(instance1, :minargs).with(1, 2){ "one-two" }
624
+ Assert.stub(instance1, :minargs).with(1, 2, 3){ "one-two-three" }
621
625
 
622
- Assert.stub(@instance, :withblock){ 'default' }
626
+ Assert.stub(instance1, :withblock){ "default" }
623
627
  end
624
- subject{ @instance }
628
+
629
+ let(:instance1) { DelegateClass.new }
625
630
 
626
631
  should "allow stubbing a method that doesn't take args" do
627
- assert_equal 'none', subject.noargs
632
+ assert_that(subject.noargs).equals("none")
628
633
  end
629
634
 
630
635
  should "allow stubbing a method that takes args" do
631
- assert_equal 'one', subject.withargs(1)
632
- assert_equal 'default', subject.withargs(2)
636
+ assert_that(subject.withargs(1)).equals("one")
637
+ assert_that(subject.withargs(2)).equals("default")
633
638
  end
634
639
 
635
640
  should "allow stubbing a method that takes any args" do
636
- assert_equal 'default', subject.anyargs
637
- assert_equal 'default', subject.anyargs(1)
638
- assert_equal 'one-two', subject.anyargs(1, 2)
641
+ assert_that(subject.anyargs).equals("default")
642
+ assert_that(subject.anyargs(1)).equals("default")
643
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
639
644
  end
640
645
 
641
646
  should "allow stubbing a method that takes a minimum number of args" do
642
- assert_equal 'one-two', subject.minargs(1, 2)
643
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
644
- assert_equal 'default', subject.minargs(1, 2, 4)
645
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
647
+ assert_that(subject.minargs(1, 2)).equals("one-two")
648
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
649
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
650
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
646
651
  end
647
652
 
648
653
  should "allow stubbing a method that takes a block" do
649
- assert_equal 'default', subject.withblock
650
- assert_equal 'default', subject.withblock{ 'my-block' }
654
+ assert_that(subject.withblock).equals("default")
655
+ assert_that(subject.withblock{ "my-block" }).equals("default")
651
656
  end
652
657
 
653
658
  should "allow stubbing methods with invalid arity" do
654
- assert_nothing_raised{ Assert.stub(subject, :noargs).with(1){ } }
659
+ assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).does_not_raise
655
660
 
656
- assert_nothing_raised{ Assert.stub(subject, :withargs).with{ } }
657
- assert_nothing_raised{ Assert.stub(subject, :withargs).with(1, 2){ } }
661
+ assert_that(-> { Assert.stub(subject, :withargs).with{ } }).does_not_raise
662
+ assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).does_not_raise
658
663
 
659
- assert_nothing_raised{ Assert.stub(subject, :minargs).with{ } }
660
- assert_nothing_raised{ Assert.stub(subject, :minargs).with(1){ } }
664
+ assert_that(-> { Assert.stub(subject, :minargs).with{ } }).does_not_raise
665
+ assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).does_not_raise
661
666
 
662
- assert_nothing_raised{ Assert.stub(subject, :withblock).with(1){ } }
667
+ assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).does_not_raise
663
668
  end
664
669
 
665
670
  should "allow calling methods with invalid arity" do
666
- assert_nothing_raised{ subject.noargs(1) }
671
+ assert_that(-> { subject.noargs(1) }).does_not_raise
667
672
 
668
- assert_nothing_raised{ subject.withargs }
669
- assert_nothing_raised{ subject.withargs(1, 2) }
673
+ assert_that(-> { subject.withargs }).does_not_raise
674
+ assert_that(-> { subject.withargs(1, 2) }).does_not_raise
670
675
 
671
- assert_nothing_raised{ subject.minargs }
672
- assert_nothing_raised{ subject.minargs(1) }
676
+ assert_that(-> { subject.minargs }).does_not_raise
677
+ assert_that(-> { subject.minargs(1) }).does_not_raise
673
678
 
674
- assert_nothing_raised{ subject.withblock(1) }
679
+ assert_that(-> { subject.withblock(1) }).does_not_raise
675
680
  end
676
-
677
681
  end
678
682
 
679
683
  class ParentAndChildClassTests < SystemTests
680
684
  desc "for a parent method stubbed on both the parent and child"
681
685
  setup do
682
- @parent_class = Class.new
683
- @child_class = Class.new(@parent_class)
684
-
685
- Assert.stub(@parent_class, :new){ 'parent' }
686
- Assert.stub(@child_class, :new){ 'child' }
686
+ Assert.stub(parent_class, :new){ "parent" }
687
+ Assert.stub(child_class, :new){ "child" }
687
688
  end
688
689
 
690
+ let(:parent_class) { Class.new }
691
+ let(:child_class) { Class.new(parent_class) }
692
+
689
693
  should "allow stubbing the methods individually" do
690
- assert_equal 'parent', @parent_class.new
691
- assert_equal 'child', @child_class.new
694
+ assert_that(parent_class.new).equals("parent")
695
+ assert_that(child_class.new).equals("child")
692
696
  end
693
-
694
697
  end
695
698
 
696
699
  class TestClass
697
-
698
700
  def self.noargs; end
699
701
  def self.withargs(a); end
700
702
  def self.anyargs(*args); end
@@ -706,27 +708,22 @@ class Assert::Stub
706
708
  def anyargs(*args); end
707
709
  def minargs(a, b, *args); end
708
710
  def withblock(&block); end
709
-
710
711
  end
711
712
 
712
713
  module TestModule
713
-
714
714
  def self.noargs; end
715
715
  def self.withargs(a); end
716
716
  def self.anyargs(*args); end
717
717
  def self.minargs(a, b, *args); end
718
718
  def self.withblock(&block); end
719
-
720
719
  end
721
720
 
722
721
  module TestMixin
723
-
724
722
  def noargs; end
725
723
  def withargs(a); end
726
724
  def anyargs(*args); end
727
725
  def minargs(a, b, *args); end
728
726
  def withblock(&block); end
729
-
730
727
  end
731
728
 
732
729
  class DelegateClass
@@ -750,5 +747,4 @@ class Assert::Stub
750
747
  @delegate.respond_to?(name) ? @delegate.send(name, *args, &block) : super
751
748
  end
752
749
  end
753
-
754
750
  end