assert 2.17.0 → 2.18.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +66 -41
- data/assert.gemspec +2 -3
- data/lib/assert.rb +0 -10
- data/lib/assert/actual_value.rb +127 -0
- data/lib/assert/assert_runner.rb +0 -3
- data/lib/assert/assertions.rb +10 -23
- data/lib/assert/cli.rb +30 -46
- data/lib/assert/config.rb +0 -4
- data/lib/assert/config_helpers.rb +0 -4
- data/lib/assert/context.rb +18 -9
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/context/setup_dsl.rb +0 -4
- data/lib/assert/context/subject_dsl.rb +23 -28
- data/lib/assert/context/suite_dsl.rb +0 -4
- data/lib/assert/context/test_dsl.rb +0 -4
- data/lib/assert/context_info.rb +0 -4
- data/lib/assert/default_runner.rb +0 -4
- data/lib/assert/default_suite.rb +0 -5
- data/lib/assert/default_view.rb +0 -4
- data/lib/assert/factory.rb +0 -3
- data/lib/assert/file_line.rb +0 -4
- data/lib/assert/macro.rb +0 -3
- data/lib/assert/macros/methods.rb +4 -10
- data/lib/assert/result.rb +2 -17
- data/lib/assert/runner.rb +0 -3
- data/lib/assert/stub.rb +15 -1
- data/lib/assert/suite.rb +0 -4
- data/lib/assert/test.rb +2 -7
- data/lib/assert/utils.rb +0 -4
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +0 -3
- data/lib/assert/view_helpers.rb +0 -11
- data/log/{.gitkeep → .keep} +0 -0
- data/test/helper.rb +23 -29
- data/test/support/factory.rb +14 -0
- data/test/support/inherited_stuff.rb +0 -2
- data/test/system/stub_tests.rb +332 -352
- data/test/system/test_tests.rb +98 -124
- data/test/unit/actual_value_tests.rb +335 -0
- data/test/unit/assert_tests.rb +121 -46
- data/test/unit/assertions/assert_block_tests.rb +30 -35
- data/test/unit/assertions/assert_empty_tests.rb +33 -35
- data/test/unit/assertions/assert_equal_tests.rb +75 -83
- data/test/unit/assertions/assert_file_exists_tests.rb +32 -36
- data/test/unit/assertions/assert_includes_tests.rb +38 -41
- data/test/unit/assertions/assert_instance_of_tests.rb +34 -37
- data/test/unit/assertions/assert_kind_of_tests.rb +34 -37
- data/test/unit/assertions/assert_match_tests.rb +34 -37
- data/test/unit/assertions/assert_nil_tests.rb +30 -35
- data/test/unit/assertions/assert_raises_tests.rb +54 -60
- data/test/unit/assertions/assert_respond_to_tests.rb +36 -39
- data/test/unit/assertions/assert_same_tests.rb +86 -88
- data/test/unit/assertions/assert_true_false_tests.rb +60 -66
- data/test/unit/assertions_tests.rb +14 -17
- data/test/unit/config_helpers_tests.rb +41 -39
- data/test/unit/config_tests.rb +38 -37
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +68 -87
- data/test/unit/context/subject_dsl_tests.rb +15 -49
- data/test/unit/context/suite_dsl_tests.rb +15 -20
- data/test/unit/context/test_dsl_tests.rb +50 -57
- data/test/unit/context_info_tests.rb +23 -18
- data/test/unit/context_tests.rb +183 -194
- data/test/unit/default_runner_tests.rb +1 -7
- data/test/unit/default_suite_tests.rb +57 -56
- data/test/unit/factory_tests.rb +5 -6
- data/test/unit/file_line_tests.rb +33 -39
- data/test/unit/macro_tests.rb +14 -18
- data/test/unit/result_tests.rb +159 -196
- data/test/unit/runner_tests.rb +64 -71
- data/test/unit/suite_tests.rb +58 -59
- data/test/unit/test_tests.rb +125 -136
- data/test/unit/utils_tests.rb +43 -54
- data/test/unit/view_helpers_tests.rb +54 -58
- data/test/unit/view_tests.rb +22 -27
- metadata +15 -10
- data/tmp/.gitkeep +0 -0
data/lib/assert/runner.rb
CHANGED
@@ -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
|
data/lib/assert/stub.rb
CHANGED
@@ -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
|
data/lib/assert/suite.rb
CHANGED
@@ -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
|
data/lib/assert/test.rb
CHANGED
@@ -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
|
-
#
|
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
|
data/lib/assert/utils.rb
CHANGED
@@ -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
|
data/lib/assert/version.rb
CHANGED
data/lib/assert/view.rb
CHANGED
@@ -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
|
data/lib/assert/view_helpers.rb
CHANGED
@@ -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
|
data/log/{.gitkeep → .keep}
RENAMED
File without changes
|
data/test/helper.rb
CHANGED
@@ -9,42 +9,36 @@ $LOAD_PATH.unshift(ROOT_PATH)
|
|
9
9
|
require "pry"
|
10
10
|
require "test/support/factory"
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
21
|
+
private
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
32
|
+
def test_run_result_count(type = nil)
|
33
|
+
test_run_results(type).count
|
34
|
+
end
|
42
35
|
|
43
|
-
|
44
|
-
|
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
|
data/test/support/factory.rb
CHANGED
@@ -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
|
data/test/system/stub_tests.rb
CHANGED
@@ -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
|
-
|
15
|
-
Assert.stub(
|
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(
|
19
|
-
Assert.stub(
|
17
|
+
Assert.stub(subject, :withargs){ "default" }
|
18
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
20
19
|
|
21
|
-
Assert.stub(
|
22
|
-
Assert.stub(
|
20
|
+
Assert.stub(subject, :anyargs){ "default" }
|
21
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
23
22
|
|
24
|
-
Assert.stub(
|
25
|
-
Assert.stub(
|
26
|
-
Assert.stub(
|
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(
|
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
|
-
|
31
|
+
assert_that(subject.noargs).equals("none")
|
34
32
|
end
|
35
33
|
|
36
34
|
should "allow stubbing a method that takes args" do
|
37
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
56
|
-
|
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
|
-
|
57
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
61
58
|
|
62
|
-
|
63
|
-
|
59
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
60
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
64
61
|
|
65
|
-
|
66
|
-
|
62
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
63
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
67
64
|
|
68
|
-
|
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
|
-
|
69
|
+
assert_that(-> { subject.noargs(1) }).raises
|
73
70
|
|
74
|
-
|
75
|
-
|
71
|
+
assert_that(-> { subject.withargs }).raises
|
72
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
76
73
|
|
77
|
-
|
78
|
-
|
74
|
+
assert_that(-> { subject.minargs }).raises
|
75
|
+
assert_that(-> { subject.minargs(1) }).raises
|
79
76
|
|
80
|
-
|
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
|
-
|
89
|
-
Assert.stub(
|
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(
|
93
|
-
Assert.stub(
|
89
|
+
Assert.stub(subject, :withargs){ "default" }
|
90
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
94
91
|
|
95
|
-
Assert.stub(
|
96
|
-
Assert.stub(
|
92
|
+
Assert.stub(subject, :anyargs){ "default" }
|
93
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
97
94
|
|
98
|
-
Assert.stub(
|
99
|
-
Assert.stub(
|
100
|
-
Assert.stub(
|
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(
|
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
|
-
|
103
|
+
assert_that(subject.noargs).equals("none")
|
108
104
|
end
|
109
105
|
|
110
106
|
should "allow stubbing a method that takes args" do
|
111
|
-
|
112
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
130
|
-
|
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
|
-
|
130
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
135
131
|
|
136
|
-
|
137
|
-
|
132
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
133
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
138
134
|
|
139
|
-
|
140
|
-
|
135
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
136
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
141
137
|
|
142
|
-
|
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
|
-
|
142
|
+
assert_that(-> { subject.noargs(1) }).raises
|
147
143
|
|
148
|
-
|
149
|
-
|
144
|
+
assert_that(-> { subject.withargs }).raises
|
145
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
150
146
|
|
151
|
-
|
152
|
-
|
147
|
+
assert_that(-> { subject.minargs }).raises
|
148
|
+
assert_that(-> { subject.minargs(1) }).raises
|
153
149
|
|
154
|
-
|
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
|
-
|
163
|
-
Assert.stub(
|
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(
|
167
|
-
Assert.stub(
|
162
|
+
Assert.stub(subject, :withargs){ "default" }
|
163
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
168
164
|
|
169
|
-
Assert.stub(
|
170
|
-
Assert.stub(
|
165
|
+
Assert.stub(subject, :anyargs){ "default" }
|
166
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
171
167
|
|
172
|
-
Assert.stub(
|
173
|
-
Assert.stub(
|
174
|
-
Assert.stub(
|
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(
|
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
|
-
|
176
|
+
assert_that(subject.noargs).equals("none")
|
182
177
|
end
|
183
178
|
|
184
179
|
should "allow stubbing a method that takes args" do
|
185
|
-
|
186
|
-
|
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
|
-
|
191
|
-
|
192
|
-
|
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
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
204
|
-
|
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
|
-
|
203
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
209
204
|
|
210
|
-
|
211
|
-
|
205
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
206
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
212
207
|
|
213
|
-
|
214
|
-
|
208
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
209
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
215
210
|
|
216
|
-
|
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
|
-
|
215
|
+
assert_that(-> { subject.noargs(1) }).raises
|
221
216
|
|
222
|
-
|
223
|
-
|
217
|
+
assert_that(-> { subject.withargs }).raises
|
218
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
224
219
|
|
225
|
-
|
226
|
-
|
220
|
+
assert_that(-> { subject.minargs }).raises
|
221
|
+
assert_that(-> { subject.minargs(1) }).raises
|
227
222
|
|
228
|
-
|
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
|
-
|
237
|
-
Assert.stub(
|
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(
|
241
|
-
Assert.stub(
|
235
|
+
Assert.stub(subject, :withargs){ "default" }
|
236
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
242
237
|
|
243
|
-
Assert.stub(
|
244
|
-
Assert.stub(
|
238
|
+
Assert.stub(subject, :anyargs){ "default" }
|
239
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
245
240
|
|
246
|
-
Assert.stub(
|
247
|
-
Assert.stub(
|
248
|
-
Assert.stub(
|
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(
|
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
|
-
|
249
|
+
assert_that(subject.noargs).equals("none")
|
256
250
|
end
|
257
251
|
|
258
252
|
should "allow stubbing a method that takes args" do
|
259
|
-
|
260
|
-
|
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
|
-
|
265
|
-
|
266
|
-
|
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
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
278
|
-
|
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
|
-
|
276
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
283
277
|
|
284
|
-
|
285
|
-
|
278
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
279
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
286
280
|
|
287
|
-
|
288
|
-
|
281
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
282
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
289
283
|
|
290
|
-
|
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
|
-
|
288
|
+
assert_that(-> { subject.noargs(1) }).raises
|
295
289
|
|
296
|
-
|
297
|
-
|
290
|
+
assert_that(-> { subject.withargs }).raises
|
291
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
298
292
|
|
299
|
-
|
300
|
-
|
293
|
+
assert_that(-> { subject.minargs }).raises
|
294
|
+
assert_that(-> { subject.minargs(1) }).raises
|
301
295
|
|
302
|
-
|
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
|
-
|
311
|
-
|
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(
|
316
|
-
Assert.stub(
|
310
|
+
Assert.stub(subject, :withargs){ "default" }
|
311
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
317
312
|
|
318
|
-
Assert.stub(
|
319
|
-
Assert.stub(
|
313
|
+
Assert.stub(subject, :anyargs){ "default" }
|
314
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
320
315
|
|
321
|
-
Assert.stub(
|
322
|
-
Assert.stub(
|
323
|
-
Assert.stub(
|
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(
|
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
|
-
|
324
|
+
assert_that(subject.noargs).equals("none")
|
331
325
|
end
|
332
326
|
|
333
327
|
should "allow stubbing a method that takes args" do
|
334
|
-
|
335
|
-
|
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
|
-
|
340
|
-
|
341
|
-
|
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
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
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
|
-
|
353
|
-
|
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
|
-
|
351
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
358
352
|
|
359
|
-
|
360
|
-
|
353
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
354
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
361
355
|
|
362
|
-
|
363
|
-
|
356
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
357
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
364
358
|
|
365
|
-
|
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
|
-
|
363
|
+
assert_that(-> { subject.noargs(1) }).raises
|
370
364
|
|
371
|
-
|
372
|
-
|
365
|
+
assert_that(-> { subject.withargs }).raises
|
366
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
373
367
|
|
374
|
-
|
375
|
-
|
368
|
+
assert_that(-> { subject.minargs }).raises
|
369
|
+
assert_that(-> { subject.minargs(1) }).raises
|
376
370
|
|
377
|
-
|
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
|
-
|
386
|
-
Assert.stub(
|
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(
|
390
|
-
Assert.stub(
|
383
|
+
Assert.stub(subject, :withargs){ "default" }
|
384
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
391
385
|
|
392
|
-
Assert.stub(
|
393
|
-
Assert.stub(
|
386
|
+
Assert.stub(subject, :anyargs){ "default" }
|
387
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
394
388
|
|
395
|
-
Assert.stub(
|
396
|
-
Assert.stub(
|
397
|
-
Assert.stub(
|
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(
|
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
|
-
|
397
|
+
assert_that(subject.noargs).equals("none")
|
405
398
|
end
|
406
399
|
|
407
400
|
should "allow stubbing a method that takes args" do
|
408
|
-
|
409
|
-
|
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
|
-
|
414
|
-
|
415
|
-
|
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
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
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
|
-
|
427
|
-
|
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
|
-
|
424
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
432
425
|
|
433
|
-
|
434
|
-
|
426
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
427
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
435
428
|
|
436
|
-
|
437
|
-
|
429
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
430
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
438
431
|
|
439
|
-
|
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
|
-
|
436
|
+
assert_that(-> { subject.noargs(1) }).raises
|
444
437
|
|
445
|
-
|
446
|
-
|
438
|
+
assert_that(-> { subject.withargs }).raises
|
439
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
447
440
|
|
448
|
-
|
449
|
-
|
441
|
+
assert_that(-> { subject.minargs }).raises
|
442
|
+
assert_that(-> { subject.minargs(1) }).raises
|
450
443
|
|
451
|
-
|
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
|
-
|
460
|
-
|
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(
|
465
|
-
Assert.stub(
|
456
|
+
Assert.stub(subject, :withargs){ "default" }
|
457
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
466
458
|
|
467
|
-
Assert.stub(
|
468
|
-
Assert.stub(
|
459
|
+
Assert.stub(subject, :anyargs){ "default" }
|
460
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
469
461
|
|
470
|
-
Assert.stub(
|
471
|
-
Assert.stub(
|
472
|
-
Assert.stub(
|
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(
|
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
|
-
|
470
|
+
assert_that(subject.noargs).equals("none")
|
480
471
|
end
|
481
472
|
|
482
473
|
should "allow stubbing a method that takes args" do
|
483
|
-
|
484
|
-
|
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
|
-
|
489
|
-
|
490
|
-
|
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
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
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
|
-
|
502
|
-
|
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
|
-
|
497
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
507
498
|
|
508
|
-
|
509
|
-
|
499
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
500
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
510
501
|
|
511
|
-
|
512
|
-
|
502
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
503
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
513
504
|
|
514
|
-
|
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
|
-
|
509
|
+
assert_that(-> { subject.noargs(1) }).raises
|
519
510
|
|
520
|
-
|
521
|
-
|
511
|
+
assert_that(-> { subject.withargs }).raises
|
512
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
522
513
|
|
523
|
-
|
524
|
-
|
514
|
+
assert_that(-> { subject.minargs }).raises
|
515
|
+
assert_that(-> { subject.minargs(1) }).raises
|
525
516
|
|
526
|
-
|
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
|
-
|
535
|
-
Assert.stub(
|
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(
|
539
|
-
Assert.stub(
|
529
|
+
Assert.stub(subject, :withargs){ "default" }
|
530
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
540
531
|
|
541
|
-
Assert.stub(
|
542
|
-
Assert.stub(
|
532
|
+
Assert.stub(subject, :anyargs){ "default" }
|
533
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
543
534
|
|
544
|
-
Assert.stub(
|
545
|
-
Assert.stub(
|
546
|
-
Assert.stub(
|
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(
|
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
|
-
|
543
|
+
assert_that(subject.noargs).equals("none")
|
554
544
|
end
|
555
545
|
|
556
546
|
should "allow stubbing a method that takes args" do
|
557
|
-
|
558
|
-
|
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
|
-
|
563
|
-
|
564
|
-
|
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
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
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
|
-
|
576
|
-
|
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
|
-
|
570
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).does_not_raise
|
581
571
|
|
582
|
-
|
583
|
-
|
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
|
-
|
586
|
-
|
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
|
-
|
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
|
-
|
582
|
+
assert_that(-> { subject.noargs(1) }).does_not_raise
|
593
583
|
|
594
|
-
|
595
|
-
|
584
|
+
assert_that(-> { subject.withargs }).does_not_raise
|
585
|
+
assert_that(-> { subject.withargs(1, 2) }).does_not_raise
|
596
586
|
|
597
|
-
|
598
|
-
|
587
|
+
assert_that(-> { subject.minargs }).does_not_raise
|
588
|
+
assert_that(-> { subject.minargs(1) }).does_not_raise
|
599
589
|
|
600
|
-
|
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
|
-
|
609
|
-
Assert.stub(
|
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(
|
613
|
-
Assert.stub(
|
602
|
+
Assert.stub(subject, :withargs){ "default" }
|
603
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
614
604
|
|
615
|
-
Assert.stub(
|
616
|
-
Assert.stub(
|
605
|
+
Assert.stub(subject, :anyargs){ "default" }
|
606
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
617
607
|
|
618
|
-
Assert.stub(
|
619
|
-
Assert.stub(
|
620
|
-
Assert.stub(
|
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(
|
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
|
-
|
616
|
+
assert_that(subject.noargs).equals("none")
|
628
617
|
end
|
629
618
|
|
630
619
|
should "allow stubbing a method that takes args" do
|
631
|
-
|
632
|
-
|
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
|
-
|
637
|
-
|
638
|
-
|
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
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
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
|
-
|
650
|
-
|
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
|
-
|
643
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).does_not_raise
|
655
644
|
|
656
|
-
|
657
|
-
|
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
|
-
|
660
|
-
|
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
|
-
|
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
|
-
|
655
|
+
assert_that(-> { subject.noargs(1) }).does_not_raise
|
667
656
|
|
668
|
-
|
669
|
-
|
657
|
+
assert_that(-> { subject.withargs }).does_not_raise
|
658
|
+
assert_that(-> { subject.withargs(1, 2) }).does_not_raise
|
670
659
|
|
671
|
-
|
672
|
-
|
660
|
+
assert_that(-> { subject.minargs }).does_not_raise
|
661
|
+
assert_that(-> { subject.minargs(1) }).does_not_raise
|
673
662
|
|
674
|
-
|
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
|
-
|
683
|
-
|
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
|
-
|
691
|
-
|
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
|