assert 2.17.0 → 2.18.4

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