assert 2.18.0 → 2.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +66 -37
- data/assert.gemspec +4 -3
- data/lib/assert/actual_value.rb +140 -0
- data/lib/assert/assertions.rb +80 -20
- data/lib/assert/context.rb +31 -37
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/context/subject_dsl.rb +23 -24
- data/lib/assert/macros/methods.rb +4 -4
- data/lib/assert/result.rb +5 -1
- data/lib/assert/stub.rb +16 -0
- data/lib/assert/suite.rb +7 -10
- data/lib/assert/test.rb +0 -8
- data/lib/assert/version.rb +1 -1
- data/test/helper.rb +23 -25
- data/test/support/factory.rb +15 -0
- data/test/system/stub_tests.rb +332 -333
- data/test/system/test_tests.rb +99 -109
- data/test/unit/actual_value_tests.rb +371 -0
- data/test/unit/assert_tests.rb +111 -43
- data/test/unit/assertions/assert_block_tests.rb +30 -31
- data/test/unit/assertions/assert_changes_tests.rb +97 -0
- data/test/unit/assertions/assert_empty_tests.rb +33 -32
- data/test/unit/assertions/assert_equal_tests.rb +94 -74
- data/test/unit/assertions/assert_file_exists_tests.rb +32 -33
- data/test/unit/assertions/assert_includes_tests.rb +38 -37
- data/test/unit/assertions/assert_instance_of_tests.rb +34 -33
- data/test/unit/assertions/assert_kind_of_tests.rb +34 -33
- data/test/unit/assertions/assert_match_tests.rb +34 -33
- data/test/unit/assertions/assert_nil_tests.rb +30 -31
- data/test/unit/assertions/assert_raises_tests.rb +55 -55
- data/test/unit/assertions/assert_respond_to_tests.rb +36 -35
- data/test/unit/assertions/assert_same_tests.rb +86 -81
- data/test/unit/assertions/assert_true_false_tests.rb +60 -60
- data/test/unit/assertions_tests.rb +26 -24
- data/test/unit/config_helpers_tests.rb +43 -38
- data/test/unit/config_tests.rb +38 -34
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +70 -81
- data/test/unit/context/subject_dsl_tests.rb +15 -43
- data/test/unit/context/suite_dsl_tests.rb +15 -16
- data/test/unit/context/test_dsl_tests.rb +50 -52
- data/test/unit/context_info_tests.rb +23 -15
- data/test/unit/context_tests.rb +184 -179
- data/test/unit/default_runner_tests.rb +2 -5
- data/test/unit/default_suite_tests.rb +57 -53
- data/test/unit/factory_tests.rb +5 -3
- data/test/unit/file_line_tests.rb +33 -35
- data/test/unit/macro_tests.rb +14 -10
- data/test/unit/result_tests.rb +159 -183
- data/test/unit/runner_tests.rb +64 -64
- data/test/unit/suite_tests.rb +56 -59
- data/test/unit/test_tests.rb +118 -139
- data/test/unit/utils_tests.rb +43 -45
- data/test/unit/view_helpers_tests.rb +54 -52
- data/test/unit/view_tests.rb +22 -23
- metadata +29 -7
data/lib/assert/context.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
require "assert/actual_value"
|
1
2
|
require "assert/assertions"
|
3
|
+
require "assert/context/let_dsl"
|
4
|
+
require "assert/context/method_missing"
|
2
5
|
require "assert/context/setup_dsl"
|
3
6
|
require "assert/context/subject_dsl"
|
4
7
|
require "assert/context/suite_dsl"
|
@@ -10,42 +13,22 @@ require "assert/suite"
|
|
10
13
|
require "assert/utils"
|
11
14
|
|
12
15
|
module Assert
|
16
|
+
# A Context is a scope for tests to run in. Contexts have setup and teardown
|
17
|
+
# blocks, subjects, and descriptions. Tests are run in the scope of a Context
|
18
|
+
# instance. Therefore, a Context should have minimal base
|
19
|
+
# logic/methods/instance_vars. The instance should remain pure to not pollute
|
20
|
+
# test scopes.
|
13
21
|
class Context
|
14
|
-
#
|
22
|
+
# Put all logic in DSL methods to keep context instances pure.
|
15
23
|
extend SetupDSL
|
16
24
|
extend SubjectDSL
|
17
25
|
extend SuiteDSL
|
18
26
|
extend TestDSL
|
27
|
+
extend LetDSL
|
28
|
+
include MethodMissing
|
19
29
|
include Assert::Assertions
|
20
30
|
include Assert::Macros::Methods
|
21
31
|
|
22
|
-
# a Context is a scope for tests to run in. Contexts have setup and
|
23
|
-
# teardown blocks, subjects, and descriptions. Tests are run in the
|
24
|
-
# scope of a Context instance. Therefore, a Context should have
|
25
|
-
# minimal base logic/methods/instance_vars. The instance should remain
|
26
|
-
# pure to not pollute test scopes.
|
27
|
-
|
28
|
-
# if a test method is added to a context manually (not using a context helper):
|
29
|
-
# capture any context info, build a test obj, and add it to the suite
|
30
|
-
def self.method_added(method_name)
|
31
|
-
if method_name.to_s =~ Suite::TEST_METHOD_REGEX
|
32
|
-
klass_method_name = "#{self}##{method_name}"
|
33
|
-
|
34
|
-
if self.suite.test_methods.include?(klass_method_name)
|
35
|
-
puts "WARNING: redefining "#{klass_method_name}""
|
36
|
-
puts " from: #{caller_locations(1,1)}"
|
37
|
-
else
|
38
|
-
self.suite.test_methods << klass_method_name
|
39
|
-
end
|
40
|
-
|
41
|
-
self.suite.on_test(Test.for_method(
|
42
|
-
method_name.to_s,
|
43
|
-
ContextInfo.new(self, nil, caller_locations(1,1)),
|
44
|
-
self.suite.config
|
45
|
-
))
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
32
|
def initialize(running_test, config, result_callback)
|
50
33
|
@__assert_running_test__ = running_test
|
51
34
|
@__assert_config__ = config
|
@@ -61,9 +44,8 @@ module Assert
|
|
61
44
|
end
|
62
45
|
end
|
63
46
|
|
64
|
-
#
|
65
|
-
#
|
66
|
-
# all other assertion helpers use this one in the end
|
47
|
+
# Check if the result is true. If so, create a new pass result, Otherwise
|
48
|
+
# create a new fail result with the desc and fail msg.
|
67
49
|
def assert(assertion, desc = nil)
|
68
50
|
if assertion
|
69
51
|
pass
|
@@ -78,8 +60,8 @@ module Assert
|
|
78
60
|
end
|
79
61
|
end
|
80
62
|
|
81
|
-
#
|
82
|
-
# result
|
63
|
+
# The opposite of assert. Check if the result is false. If so, create a new
|
64
|
+
# pass result. Otherwise create a new fail result with the desc and fail msg.
|
83
65
|
def assert_not(assertion, fail_desc = nil)
|
84
66
|
assert(!assertion, fail_desc) do
|
85
67
|
"Failed assert_not: assertion was "\
|
@@ -88,14 +70,23 @@ module Assert
|
|
88
70
|
end
|
89
71
|
alias_method :refute, :assert_not
|
90
72
|
|
73
|
+
def assert_that(
|
74
|
+
actual_value = Assert::ActualValue.not_given,
|
75
|
+
&actual_value_block
|
76
|
+
)
|
77
|
+
Assert::ActualValue.new(actual_value, context: self, &actual_value_block)
|
78
|
+
end
|
79
|
+
|
91
80
|
# adds a Pass result to the end of the test's results
|
92
81
|
# does not break test execution
|
93
82
|
def pass(pass_msg = nil)
|
94
83
|
if @__assert_pending__ == 0
|
95
84
|
capture_result(Assert::Result::Pass, pass_msg)
|
96
85
|
else
|
97
|
-
capture_result(
|
98
|
-
|
86
|
+
capture_result(
|
87
|
+
Assert::Result::Fail,
|
88
|
+
"Pending pass (make it not pending)"
|
89
|
+
)
|
99
90
|
end
|
100
91
|
end
|
101
92
|
|
@@ -157,9 +148,12 @@ module Assert
|
|
157
148
|
end
|
158
149
|
|
159
150
|
def subject
|
160
|
-
|
161
|
-
|
151
|
+
unless instance_variable_defined?("@__assert_subject__")
|
152
|
+
@__assert_subject__ =
|
153
|
+
instance_eval(&self.class.subject) if self.class.subject
|
162
154
|
end
|
155
|
+
|
156
|
+
@__assert_subject__
|
163
157
|
end
|
164
158
|
|
165
159
|
def inspect
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Assert; end
|
2
|
+
class Assert::Context; end
|
3
|
+
module Assert::Context::LetDSL
|
4
|
+
def let(name, &block)
|
5
|
+
self.send(:define_method, name, &-> {
|
6
|
+
unless instance_variable_defined?("@__assert_let_#{name}__")
|
7
|
+
instance_variable_set("@__assert_let_#{name}__", instance_eval(&block))
|
8
|
+
end
|
9
|
+
|
10
|
+
instance_variable_get("@__assert_let_#{name}__")
|
11
|
+
})
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "assert/assertions"
|
2
|
+
|
3
|
+
module Assert; end
|
4
|
+
class Assert::Context; end
|
5
|
+
module Assert::Context::MethodMissing
|
6
|
+
def method_missing(method, *args, &block)
|
7
|
+
if Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
|
8
|
+
ignore "The assertion `#{method}` is not supported."\
|
9
|
+
" Please use another assertion or the basic `assert`."
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_to_missing?(method, *)
|
16
|
+
Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym) ||
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
@@ -1,33 +1,32 @@
|
|
1
1
|
module Assert; end
|
2
|
-
class Assert::Context
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
2
|
+
class Assert::Context; end
|
3
|
+
module Assert::Context::SubjectDSL
|
4
|
+
# Add a piece of description text or return the full description for the context
|
5
|
+
def description(text = nil)
|
6
|
+
if text
|
7
|
+
self.descriptions << text.to_s
|
8
|
+
else
|
9
|
+
parent = self.superclass.desc if self.superclass.respond_to?(:desc)
|
10
|
+
own = self.descriptions
|
11
|
+
[parent, *own].compact.reject(&:empty?).join(" ")
|
13
12
|
end
|
14
|
-
|
15
|
-
|
13
|
+
end
|
14
|
+
alias_method :desc, :description
|
15
|
+
alias_method :describe, :description
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
17
|
+
def subject(&block)
|
18
|
+
if block_given?
|
19
|
+
@subject = block
|
20
|
+
else
|
21
|
+
@subject || if superclass.respond_to?(:subject)
|
22
|
+
superclass.subject
|
24
23
|
end
|
25
24
|
end
|
25
|
+
end
|
26
26
|
|
27
|
-
|
27
|
+
protected
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
29
|
+
def descriptions
|
30
|
+
@descriptions ||= []
|
32
31
|
end
|
33
32
|
end
|
@@ -102,28 +102,28 @@ module Assert::Macros
|
|
102
102
|
self.class._methods_macro_instance_methods.each do |(method, called_from)|
|
103
103
|
msg = "#{subject.class.name} does not have instance method ##{method}"
|
104
104
|
with_backtrace([called_from]) do
|
105
|
-
|
105
|
+
assert_that(subject).responds_to(method, msg)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
self.class._methods_macro_class_methods.each do |(method, called_from)|
|
110
110
|
msg = "#{subject.class.name} does not have class method ##{method}"
|
111
111
|
with_backtrace([called_from]) do
|
112
|
-
|
112
|
+
assert_that(subject.class).responds_to(method, msg)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
116
|
self.class._methods_macro_not_instance_methods.each do |(method, called_from)|
|
117
117
|
msg = "#{subject.class.name} has instance method ##{method}"
|
118
118
|
with_backtrace([called_from]) do
|
119
|
-
|
119
|
+
assert_that(subject).does_not_respond_to(method, msg)
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
123
|
self.class._methods_macro_not_class_methods.each do |(method, called_from)|
|
124
124
|
msg = "#{subject.class.name} has class method ##{method}"
|
125
125
|
with_backtrace([called_from]) do
|
126
|
-
|
126
|
+
assert_that(subject.class).does_not_respond_to(method, msg)
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
data/lib/assert/result.rb
CHANGED
@@ -129,7 +129,11 @@ module Assert::Result
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def ==(other_result)
|
132
|
-
|
132
|
+
if other_result.is_a?(self.class)
|
133
|
+
self.type == other_result.type && self.message == other_result.message
|
134
|
+
else
|
135
|
+
super
|
136
|
+
end
|
133
137
|
end
|
134
138
|
|
135
139
|
def inspect
|
data/lib/assert/stub.rb
CHANGED
@@ -9,6 +9,10 @@ module Assert
|
|
9
9
|
MuchStub.stub(*args, &block)
|
10
10
|
end
|
11
11
|
|
12
|
+
def self.stub_on_call(*args, &block)
|
13
|
+
MuchStub.stub_on_call(*args, &block)
|
14
|
+
end
|
15
|
+
|
12
16
|
def self.unstub(*args)
|
13
17
|
MuchStub.unstub(*args)
|
14
18
|
end
|
@@ -26,4 +30,16 @@ module Assert
|
|
26
30
|
raise err
|
27
31
|
end
|
28
32
|
end
|
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
|
29
45
|
end
|
data/lib/assert/suite.rb
CHANGED
@@ -10,22 +10,19 @@ module Assert
|
|
10
10
|
class Suite
|
11
11
|
include Assert::ConfigHelpers
|
12
12
|
|
13
|
-
TEST_METHOD_REGEX = /^test./.freeze
|
14
|
-
|
15
13
|
# A suite is a set of tests to run. When a test class subclasses
|
16
14
|
# the Context class, that test class is pushed to the suite.
|
17
15
|
|
18
|
-
attr_reader :config, :
|
16
|
+
attr_reader :config, :setups, :teardowns
|
19
17
|
attr_accessor :start_time, :end_time
|
20
18
|
|
21
19
|
def initialize(config)
|
22
|
-
@config
|
23
|
-
@tests
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@
|
27
|
-
@
|
28
|
-
@end_time = @start_time
|
20
|
+
@config = config
|
21
|
+
@tests = []
|
22
|
+
@setups = []
|
23
|
+
@teardowns = []
|
24
|
+
@start_time = Time.now
|
25
|
+
@end_time = @start_time
|
29
26
|
end
|
30
27
|
|
31
28
|
def suite; self; end
|
data/lib/assert/test.rb
CHANGED
@@ -20,14 +20,6 @@ module Assert
|
|
20
20
|
}))
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.for_method(method_name, context_info, config)
|
24
|
-
self.new(self.name_file_line_context_data(context_info, method_name).merge({
|
25
|
-
:context_info => context_info,
|
26
|
-
:config => config,
|
27
|
-
:code => proc{ self.send(method_name) }
|
28
|
-
}))
|
29
|
-
end
|
30
|
-
|
31
23
|
def initialize(build_data = nil)
|
32
24
|
@build_data = build_data || {}
|
33
25
|
@result_callback = nil
|
data/lib/assert/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -9,38 +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
|
-
@run_callback = proc{ |result| @test_run_results << result }
|
19
|
-
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 }
|
20
18
|
end
|
19
|
+
end
|
21
20
|
|
22
|
-
|
21
|
+
private
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def test_run_callback
|
24
|
+
@run_callback
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def test_run_result_count(type = nil)
|
33
|
+
test_run_results(type).count
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def test_run_result_messages
|
37
|
+
@test_run_results.map(&:message)
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
40
|
+
def last_test_run_result
|
41
|
+
@test_run_results.last
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
data/test/support/factory.rb
CHANGED
@@ -85,4 +85,19 @@ module Factory
|
|
85
85
|
instance_eval(&block) if !block.nil?
|
86
86
|
end
|
87
87
|
end
|
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
|
88
103
|
end
|
data/test/system/stub_tests.rb
CHANGED
@@ -8,676 +8,675 @@ class Assert::Stub
|
|
8
8
|
|
9
9
|
class InstanceTests < SystemTests
|
10
10
|
desc "for instance methods"
|
11
|
+
subject { TestClass.new }
|
12
|
+
|
11
13
|
setup do
|
12
|
-
|
13
|
-
Assert.stub(
|
14
|
-
Assert.stub(@instance, :noargs).with{ "none" }
|
14
|
+
Assert.stub(subject, :noargs){ "default" }
|
15
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
15
16
|
|
16
|
-
Assert.stub(
|
17
|
-
Assert.stub(
|
17
|
+
Assert.stub(subject, :withargs){ "default" }
|
18
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
18
19
|
|
19
|
-
Assert.stub(
|
20
|
-
Assert.stub(
|
20
|
+
Assert.stub(subject, :anyargs){ "default" }
|
21
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
21
22
|
|
22
|
-
Assert.stub(
|
23
|
-
Assert.stub(
|
24
|
-
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" }
|
25
26
|
|
26
|
-
Assert.stub(
|
27
|
+
Assert.stub(subject, :withblock){ "default" }
|
27
28
|
end
|
28
|
-
subject{ @instance }
|
29
29
|
|
30
30
|
should "allow stubbing a method that doesn't take args" do
|
31
|
-
|
31
|
+
assert_that(subject.noargs).equals("none")
|
32
32
|
end
|
33
33
|
|
34
34
|
should "allow stubbing a method that takes args" do
|
35
|
-
|
36
|
-
assert_equal "default", subject.withargs(2)
|
35
|
+
assert_that(subject.withargs(2)).equals("default")
|
37
36
|
end
|
38
37
|
|
39
38
|
should "allow stubbing a method that takes any args" do
|
40
|
-
|
41
|
-
|
42
|
-
|
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")
|
43
42
|
end
|
44
43
|
|
45
44
|
should "allow stubbing a method that takes a minimum number of args" do
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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")
|
50
49
|
end
|
51
50
|
|
52
51
|
should "allow stubbing a method that takes a block" do
|
53
|
-
|
54
|
-
|
52
|
+
assert_that(subject.withblock).equals("default")
|
53
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
55
54
|
end
|
56
55
|
|
57
56
|
should "not allow stubbing methods with invalid arity" do
|
58
|
-
|
57
|
+
assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
|
59
58
|
|
60
|
-
|
61
|
-
|
59
|
+
assert_that { Assert.stub(subject, :withargs).with{ } }.raises
|
60
|
+
assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
|
62
61
|
|
63
|
-
|
64
|
-
|
62
|
+
assert_that { Assert.stub(subject, :minargs).with{ } }.raises
|
63
|
+
assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
|
65
64
|
|
66
|
-
|
65
|
+
assert_that { Assert.stub(subject, :withblock).with(1){ } }.raises
|
67
66
|
end
|
68
67
|
|
69
68
|
should "not allow calling methods with invalid arity" do
|
70
|
-
|
69
|
+
assert_that { subject.noargs(1) }.raises
|
71
70
|
|
72
|
-
|
73
|
-
|
71
|
+
assert_that { subject.withargs }.raises
|
72
|
+
assert_that { subject.withargs(1, 2) }.raises
|
74
73
|
|
75
|
-
|
76
|
-
|
74
|
+
assert_that { subject.minargs }.raises
|
75
|
+
assert_that { subject.minargs(1) }.raises
|
77
76
|
|
78
|
-
|
77
|
+
assert_that { subject.withblock(1) }.raises
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
82
81
|
class ClassTests < SystemTests
|
83
82
|
desc "for singleton methods on a class"
|
83
|
+
subject { TestClass }
|
84
|
+
|
84
85
|
setup do
|
85
|
-
|
86
|
-
Assert.stub(
|
87
|
-
Assert.stub(@class, :noargs).with{ "none" }
|
86
|
+
Assert.stub(subject, :noargs){ "default" }
|
87
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
88
88
|
|
89
|
-
Assert.stub(
|
90
|
-
Assert.stub(
|
89
|
+
Assert.stub(subject, :withargs){ "default" }
|
90
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
91
91
|
|
92
|
-
Assert.stub(
|
93
|
-
Assert.stub(
|
92
|
+
Assert.stub(subject, :anyargs){ "default" }
|
93
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
94
94
|
|
95
|
-
Assert.stub(
|
96
|
-
Assert.stub(
|
97
|
-
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" }
|
98
98
|
|
99
|
-
Assert.stub(
|
99
|
+
Assert.stub(subject, :withblock){ "default" }
|
100
100
|
end
|
101
|
-
subject{ @class }
|
102
101
|
|
103
102
|
should "allow stubbing a method that doesn't take args" do
|
104
|
-
|
103
|
+
assert_that(subject.noargs).equals("none")
|
105
104
|
end
|
106
105
|
|
107
106
|
should "allow stubbing a method that takes args" do
|
108
|
-
|
109
|
-
|
107
|
+
assert_that(subject.withargs(1)).equals("one")
|
108
|
+
assert_that(subject.withargs(2)).equals("default")
|
110
109
|
end
|
111
110
|
|
112
111
|
should "allow stubbing a method that takes any args" do
|
113
|
-
|
114
|
-
|
115
|
-
|
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")
|
116
115
|
end
|
117
116
|
|
118
117
|
should "allow stubbing a method that takes a minimum number of args" do
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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")
|
123
122
|
end
|
124
123
|
|
125
124
|
should "allow stubbing a method that takes a block" do
|
126
|
-
|
127
|
-
|
125
|
+
assert_that(subject.withblock).equals("default")
|
126
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
128
127
|
end
|
129
128
|
|
130
129
|
should "not allow stubbing methods with invalid arity" do
|
131
|
-
|
130
|
+
assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
|
132
131
|
|
133
|
-
|
134
|
-
|
132
|
+
assert_that { Assert.stub(subject, :withargs).with{ } }.raises
|
133
|
+
assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
|
135
134
|
|
136
|
-
|
137
|
-
|
135
|
+
assert_that { Assert.stub(subject, :minargs).with{ } }.raises
|
136
|
+
assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
|
138
137
|
|
139
|
-
|
138
|
+
assert_that { Assert.stub(subject, :withblock).with(1){ } }.raises
|
140
139
|
end
|
141
140
|
|
142
141
|
should "not allow calling methods with invalid arity" do
|
143
|
-
|
142
|
+
assert_that { subject.noargs(1) }.raises
|
144
143
|
|
145
|
-
|
146
|
-
|
144
|
+
assert_that { subject.withargs }.raises
|
145
|
+
assert_that { subject.withargs(1, 2) }.raises
|
147
146
|
|
148
|
-
|
149
|
-
|
147
|
+
assert_that { subject.minargs }.raises
|
148
|
+
assert_that { subject.minargs(1) }.raises
|
150
149
|
|
151
|
-
|
150
|
+
assert_that { subject.withblock(1) }.raises
|
152
151
|
end
|
153
152
|
end
|
154
153
|
|
155
154
|
class ModuleTests < SystemTests
|
156
155
|
desc "for singleton methods on a module"
|
156
|
+
subject { TestModule }
|
157
|
+
|
157
158
|
setup do
|
158
|
-
|
159
|
-
Assert.stub(
|
160
|
-
Assert.stub(@module, :noargs).with{ "none" }
|
159
|
+
Assert.stub(subject, :noargs){ "default" }
|
160
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
161
161
|
|
162
|
-
Assert.stub(
|
163
|
-
Assert.stub(
|
162
|
+
Assert.stub(subject, :withargs){ "default" }
|
163
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
164
164
|
|
165
|
-
Assert.stub(
|
166
|
-
Assert.stub(
|
165
|
+
Assert.stub(subject, :anyargs){ "default" }
|
166
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
167
167
|
|
168
|
-
Assert.stub(
|
169
|
-
Assert.stub(
|
170
|
-
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" }
|
171
171
|
|
172
|
-
Assert.stub(
|
172
|
+
Assert.stub(subject, :withblock){ "default" }
|
173
173
|
end
|
174
|
-
subject{ @module }
|
175
174
|
|
176
175
|
should "allow stubbing a method that doesn't take args" do
|
177
|
-
|
176
|
+
assert_that(subject.noargs).equals("none")
|
178
177
|
end
|
179
178
|
|
180
179
|
should "allow stubbing a method that takes args" do
|
181
|
-
|
182
|
-
|
180
|
+
assert_that(subject.withargs(1)).equals("one")
|
181
|
+
assert_that(subject.withargs(2)).equals("default")
|
183
182
|
end
|
184
183
|
|
185
184
|
should "allow stubbing a method that takes any args" do
|
186
|
-
|
187
|
-
|
188
|
-
|
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")
|
189
188
|
end
|
190
189
|
|
191
190
|
should "allow stubbing a method that takes a minimum number of args" do
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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")
|
196
195
|
end
|
197
196
|
|
198
197
|
should "allow stubbing a method that takes a block" do
|
199
|
-
|
200
|
-
|
198
|
+
assert_that(subject.withblock).equals("default")
|
199
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
201
200
|
end
|
202
201
|
|
203
202
|
should "not allow stubbing methods with invalid arity" do
|
204
|
-
|
203
|
+
assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
|
205
204
|
|
206
|
-
|
207
|
-
|
205
|
+
assert_that { Assert.stub(subject, :withargs).with{ } }.raises
|
206
|
+
assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
|
208
207
|
|
209
|
-
|
210
|
-
|
208
|
+
assert_that { Assert.stub(subject, :minargs).with{ } }.raises
|
209
|
+
assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
|
211
210
|
|
212
|
-
|
211
|
+
assert_that { Assert.stub(subject, :withblock).with(1){ } }.raises
|
213
212
|
end
|
214
213
|
|
215
214
|
should "not allow calling methods with invalid arity" do
|
216
|
-
|
215
|
+
assert_that { subject.noargs(1) }.raises
|
217
216
|
|
218
|
-
|
219
|
-
|
217
|
+
assert_that { subject.withargs }.raises
|
218
|
+
assert_that { subject.withargs(1, 2) }.raises
|
220
219
|
|
221
|
-
|
222
|
-
|
220
|
+
assert_that { subject.minargs }.raises
|
221
|
+
assert_that { subject.minargs(1) }.raises
|
223
222
|
|
224
|
-
|
223
|
+
assert_that { subject.withblock(1) }.raises
|
225
224
|
end
|
226
225
|
end
|
227
226
|
|
228
227
|
class ExtendedTests < SystemTests
|
229
228
|
desc "for extended methods"
|
229
|
+
subject { Class.new{ extend TestMixin } }
|
230
|
+
|
230
231
|
setup do
|
231
|
-
|
232
|
-
Assert.stub(
|
233
|
-
Assert.stub(@class, :noargs).with{ "none" }
|
232
|
+
Assert.stub(subject, :noargs){ "default" }
|
233
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
234
234
|
|
235
|
-
Assert.stub(
|
236
|
-
Assert.stub(
|
235
|
+
Assert.stub(subject, :withargs){ "default" }
|
236
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
237
237
|
|
238
|
-
Assert.stub(
|
239
|
-
Assert.stub(
|
238
|
+
Assert.stub(subject, :anyargs){ "default" }
|
239
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
240
240
|
|
241
|
-
Assert.stub(
|
242
|
-
Assert.stub(
|
243
|
-
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" }
|
244
244
|
|
245
|
-
Assert.stub(
|
245
|
+
Assert.stub(subject, :withblock){ "default" }
|
246
246
|
end
|
247
|
-
subject{ @class }
|
248
247
|
|
249
248
|
should "allow stubbing a method that doesn't take args" do
|
250
|
-
|
249
|
+
assert_that(subject.noargs).equals("none")
|
251
250
|
end
|
252
251
|
|
253
252
|
should "allow stubbing a method that takes args" do
|
254
|
-
|
255
|
-
|
253
|
+
assert_that(subject.withargs(1)).equals("one")
|
254
|
+
assert_that(subject.withargs(2)).equals("default")
|
256
255
|
end
|
257
256
|
|
258
257
|
should "allow stubbing a method that takes any args" do
|
259
|
-
|
260
|
-
|
261
|
-
|
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")
|
262
261
|
end
|
263
262
|
|
264
263
|
should "allow stubbing a method that takes a minimum number of args" do
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
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")
|
269
268
|
end
|
270
269
|
|
271
270
|
should "allow stubbing a method that takes a block" do
|
272
|
-
|
273
|
-
|
271
|
+
assert_that(subject.withblock).equals("default")
|
272
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
274
273
|
end
|
275
274
|
|
276
275
|
should "not allow stubbing methods with invalid arity" do
|
277
|
-
|
276
|
+
assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
|
278
277
|
|
279
|
-
|
280
|
-
|
278
|
+
assert_that { Assert.stub(subject, :withargs).with{ } }.raises
|
279
|
+
assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
|
281
280
|
|
282
|
-
|
283
|
-
|
281
|
+
assert_that { Assert.stub(subject, :minargs).with{ } }.raises
|
282
|
+
assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
|
284
283
|
|
285
|
-
|
284
|
+
assert_that { Assert.stub(subject, :withblock).with(1){ } }.raises
|
286
285
|
end
|
287
286
|
|
288
287
|
should "not allow calling methods with invalid arity" do
|
289
|
-
|
288
|
+
assert_that { subject.noargs(1) }.raises
|
290
289
|
|
291
|
-
|
292
|
-
|
290
|
+
assert_that { subject.withargs }.raises
|
291
|
+
assert_that { subject.withargs(1, 2) }.raises
|
293
292
|
|
294
|
-
|
295
|
-
|
293
|
+
assert_that { subject.minargs }.raises
|
294
|
+
assert_that { subject.minargs(1) }.raises
|
296
295
|
|
297
|
-
|
296
|
+
assert_that { subject.withblock(1) }.raises
|
298
297
|
end
|
299
298
|
end
|
300
299
|
|
301
300
|
class IncludedTests < SystemTests
|
302
301
|
desc "for an included method"
|
302
|
+
subject {
|
303
|
+
Class.new { include TestMixin }.new
|
304
|
+
}
|
305
|
+
|
303
306
|
setup do
|
304
|
-
|
305
|
-
|
306
|
-
Assert.stub(@instance, :noargs){ "default" }
|
307
|
-
Assert.stub(@instance, :noargs).with{ "none" }
|
307
|
+
Assert.stub(subject, :noargs){ "default" }
|
308
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
308
309
|
|
309
|
-
Assert.stub(
|
310
|
-
Assert.stub(
|
310
|
+
Assert.stub(subject, :withargs){ "default" }
|
311
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
311
312
|
|
312
|
-
Assert.stub(
|
313
|
-
Assert.stub(
|
313
|
+
Assert.stub(subject, :anyargs){ "default" }
|
314
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
314
315
|
|
315
|
-
Assert.stub(
|
316
|
-
Assert.stub(
|
317
|
-
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" }
|
318
319
|
|
319
|
-
Assert.stub(
|
320
|
+
Assert.stub(subject, :withblock){ "default" }
|
320
321
|
end
|
321
|
-
subject{ @instance }
|
322
322
|
|
323
323
|
should "allow stubbing a method that doesn't take args" do
|
324
|
-
|
324
|
+
assert_that(subject.noargs).equals("none")
|
325
325
|
end
|
326
326
|
|
327
327
|
should "allow stubbing a method that takes args" do
|
328
|
-
|
329
|
-
|
328
|
+
assert_that(subject.withargs(1)).equals("one")
|
329
|
+
assert_that(subject.withargs(2)).equals("default")
|
330
330
|
end
|
331
331
|
|
332
332
|
should "allow stubbing a method that takes any args" do
|
333
|
-
|
334
|
-
|
335
|
-
|
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")
|
336
336
|
end
|
337
337
|
|
338
338
|
should "allow stubbing a method that takes a minimum number of args" do
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
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")
|
343
343
|
end
|
344
344
|
|
345
345
|
should "allow stubbing a method that takes a block" do
|
346
|
-
|
347
|
-
|
346
|
+
assert_that(subject.withblock).equals("default")
|
347
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
348
348
|
end
|
349
349
|
|
350
350
|
should "not allow stubbing methods with invalid arity" do
|
351
|
-
|
351
|
+
assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
|
352
352
|
|
353
|
-
|
354
|
-
|
353
|
+
assert_that { Assert.stub(subject, :withargs).with{ } }.raises
|
354
|
+
assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
|
355
355
|
|
356
|
-
|
357
|
-
|
356
|
+
assert_that { Assert.stub(subject, :minargs).with{ } }.raises
|
357
|
+
assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
|
358
358
|
|
359
|
-
|
359
|
+
assert_that { Assert.stub(subject, :withblock).with(1){ } }.raises
|
360
360
|
end
|
361
361
|
|
362
362
|
should "not allow calling methods with invalid arity" do
|
363
|
-
|
363
|
+
assert_that { subject.noargs(1) }.raises
|
364
364
|
|
365
|
-
|
366
|
-
|
365
|
+
assert_that { subject.withargs }.raises
|
366
|
+
assert_that { subject.withargs(1, 2) }.raises
|
367
367
|
|
368
|
-
|
369
|
-
|
368
|
+
assert_that { subject.minargs }.raises
|
369
|
+
assert_that { subject.minargs(1) }.raises
|
370
370
|
|
371
|
-
|
371
|
+
assert_that { subject.withblock(1) }.raises
|
372
372
|
end
|
373
373
|
end
|
374
374
|
|
375
375
|
class InheritedClassTests < SystemTests
|
376
376
|
desc "for an inherited class method"
|
377
|
+
subject { Class.new(TestClass) }
|
378
|
+
|
377
379
|
setup do
|
378
|
-
|
379
|
-
Assert.stub(
|
380
|
-
Assert.stub(@class, :noargs).with{ "none" }
|
380
|
+
Assert.stub(subject, :noargs){ "default" }
|
381
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
381
382
|
|
382
|
-
Assert.stub(
|
383
|
-
Assert.stub(
|
383
|
+
Assert.stub(subject, :withargs){ "default" }
|
384
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
384
385
|
|
385
|
-
Assert.stub(
|
386
|
-
Assert.stub(
|
386
|
+
Assert.stub(subject, :anyargs){ "default" }
|
387
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
387
388
|
|
388
|
-
Assert.stub(
|
389
|
-
Assert.stub(
|
390
|
-
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" }
|
391
392
|
|
392
|
-
Assert.stub(
|
393
|
+
Assert.stub(subject, :withblock){ "default" }
|
393
394
|
end
|
394
|
-
subject{ @class }
|
395
395
|
|
396
396
|
should "allow stubbing a method that doesn't take args" do
|
397
|
-
|
397
|
+
assert_that(subject.noargs).equals("none")
|
398
398
|
end
|
399
399
|
|
400
400
|
should "allow stubbing a method that takes args" do
|
401
|
-
|
402
|
-
|
401
|
+
assert_that(subject.withargs(1)).equals("one")
|
402
|
+
assert_that(subject.withargs(2)).equals("default")
|
403
403
|
end
|
404
404
|
|
405
405
|
should "allow stubbing a method that takes any args" do
|
406
|
-
|
407
|
-
|
408
|
-
|
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")
|
409
409
|
end
|
410
410
|
|
411
411
|
should "allow stubbing a method that takes a minimum number of args" do
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
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")
|
416
416
|
end
|
417
417
|
|
418
418
|
should "allow stubbing a method that takes a block" do
|
419
|
-
|
420
|
-
|
419
|
+
assert_that(subject.withblock).equals("default")
|
420
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
421
421
|
end
|
422
422
|
|
423
423
|
should "not allow stubbing methods with invalid arity" do
|
424
|
-
|
424
|
+
assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
|
425
425
|
|
426
|
-
|
427
|
-
|
426
|
+
assert_that { Assert.stub(subject, :withargs).with{ } }.raises
|
427
|
+
assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
|
428
428
|
|
429
|
-
|
430
|
-
|
429
|
+
assert_that { Assert.stub(subject, :minargs).with{ } }.raises
|
430
|
+
assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
|
431
431
|
|
432
|
-
|
432
|
+
assert_that { Assert.stub(subject, :withblock).with(1){ } }.raises
|
433
433
|
end
|
434
434
|
|
435
435
|
should "not allow calling methods with invalid arity" do
|
436
|
-
|
436
|
+
assert_that { subject.noargs(1) }.raises
|
437
437
|
|
438
|
-
|
439
|
-
|
438
|
+
assert_that { subject.withargs }.raises
|
439
|
+
assert_that { subject.withargs(1, 2) }.raises
|
440
440
|
|
441
|
-
|
442
|
-
|
441
|
+
assert_that { subject.minargs }.raises
|
442
|
+
assert_that { subject.minargs(1) }.raises
|
443
443
|
|
444
|
-
|
444
|
+
assert_that { subject.withblock(1) }.raises
|
445
445
|
end
|
446
446
|
end
|
447
447
|
|
448
448
|
class InheritedInstanceTests < SystemTests
|
449
449
|
desc "for an inherited instance method"
|
450
|
+
subject { Class.new(TestClass).new }
|
451
|
+
|
450
452
|
setup do
|
451
|
-
|
452
|
-
|
453
|
-
Assert.stub(@instance, :noargs){ "default" }
|
454
|
-
Assert.stub(@instance, :noargs).with{ "none" }
|
453
|
+
Assert.stub(subject, :noargs){ "default" }
|
454
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
455
455
|
|
456
|
-
Assert.stub(
|
457
|
-
Assert.stub(
|
456
|
+
Assert.stub(subject, :withargs){ "default" }
|
457
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
458
458
|
|
459
|
-
Assert.stub(
|
460
|
-
Assert.stub(
|
459
|
+
Assert.stub(subject, :anyargs){ "default" }
|
460
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
461
461
|
|
462
|
-
Assert.stub(
|
463
|
-
Assert.stub(
|
464
|
-
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" }
|
465
465
|
|
466
|
-
Assert.stub(
|
466
|
+
Assert.stub(subject, :withblock){ "default" }
|
467
467
|
end
|
468
|
-
subject{ @instance }
|
469
468
|
|
470
469
|
should "allow stubbing a method that doesn't take args" do
|
471
|
-
|
470
|
+
assert_that(subject.noargs).equals("none")
|
472
471
|
end
|
473
472
|
|
474
473
|
should "allow stubbing a method that takes args" do
|
475
|
-
|
476
|
-
|
474
|
+
assert_that(subject.withargs(1)).equals("one")
|
475
|
+
assert_that(subject.withargs(2)).equals("default")
|
477
476
|
end
|
478
477
|
|
479
478
|
should "allow stubbing a method that takes any args" do
|
480
|
-
|
481
|
-
|
482
|
-
|
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")
|
483
482
|
end
|
484
483
|
|
485
484
|
should "allow stubbing a method that takes a minimum number of args" do
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
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")
|
490
489
|
end
|
491
490
|
|
492
491
|
should "allow stubbing a method that takes a block" do
|
493
|
-
|
494
|
-
|
492
|
+
assert_that(subject.withblock).equals("default")
|
493
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
495
494
|
end
|
496
495
|
|
497
496
|
should "not allow stubbing methods with invalid arity" do
|
498
|
-
|
497
|
+
assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
|
499
498
|
|
500
|
-
|
501
|
-
|
499
|
+
assert_that { Assert.stub(subject, :withargs).with{ } }.raises
|
500
|
+
assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
|
502
501
|
|
503
|
-
|
504
|
-
|
502
|
+
assert_that { Assert.stub(subject, :minargs).with{ } }.raises
|
503
|
+
assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
|
505
504
|
|
506
|
-
|
505
|
+
assert_that { Assert.stub(subject, :withblock).with(1){ } }.raises
|
507
506
|
end
|
508
507
|
|
509
508
|
should "not allow calling methods with invalid arity" do
|
510
|
-
|
509
|
+
assert_that { subject.noargs(1) }.raises
|
511
510
|
|
512
|
-
|
513
|
-
|
511
|
+
assert_that { subject.withargs }.raises
|
512
|
+
assert_that { subject.withargs(1, 2) }.raises
|
514
513
|
|
515
|
-
|
516
|
-
|
514
|
+
assert_that { subject.minargs }.raises
|
515
|
+
assert_that { subject.minargs(1) }.raises
|
517
516
|
|
518
|
-
|
517
|
+
assert_that { subject.withblock(1) }.raises
|
519
518
|
end
|
520
519
|
end
|
521
520
|
|
522
521
|
class DelegateClassTests < SystemTests
|
523
522
|
desc "a class that delegates another object"
|
523
|
+
subject { DelegateClass }
|
524
|
+
|
524
525
|
setup do
|
525
|
-
|
526
|
-
Assert.stub(
|
527
|
-
Assert.stub(@class, :noargs).with{ "none" }
|
526
|
+
Assert.stub(subject, :noargs){ "default" }
|
527
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
528
528
|
|
529
|
-
Assert.stub(
|
530
|
-
Assert.stub(
|
529
|
+
Assert.stub(subject, :withargs){ "default" }
|
530
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
531
531
|
|
532
|
-
Assert.stub(
|
533
|
-
Assert.stub(
|
532
|
+
Assert.stub(subject, :anyargs){ "default" }
|
533
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
534
534
|
|
535
|
-
Assert.stub(
|
536
|
-
Assert.stub(
|
537
|
-
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" }
|
538
538
|
|
539
|
-
Assert.stub(
|
539
|
+
Assert.stub(subject, :withblock){ "default" }
|
540
540
|
end
|
541
|
-
subject{ @class }
|
542
541
|
|
543
542
|
should "allow stubbing a method that doesn't take args" do
|
544
|
-
|
543
|
+
assert_that(subject.noargs).equals("none")
|
545
544
|
end
|
546
545
|
|
547
546
|
should "allow stubbing a method that takes args" do
|
548
|
-
|
549
|
-
|
547
|
+
assert_that(subject.withargs(1)).equals("one")
|
548
|
+
assert_that(subject.withargs(2)).equals("default")
|
550
549
|
end
|
551
550
|
|
552
551
|
should "allow stubbing a method that takes any args" do
|
553
|
-
|
554
|
-
|
555
|
-
|
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")
|
556
555
|
end
|
557
556
|
|
558
557
|
should "allow stubbing a method that takes a minimum number of args" do
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
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")
|
563
562
|
end
|
564
563
|
|
565
564
|
should "allow stubbing a method that takes a block" do
|
566
|
-
|
567
|
-
|
565
|
+
assert_that(subject.withblock).equals("default")
|
566
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
568
567
|
end
|
569
568
|
|
570
569
|
should "allow stubbing methods with invalid arity" do
|
571
|
-
|
570
|
+
assert_that { Assert.stub(subject, :noargs).with(1){ } }.does_not_raise
|
572
571
|
|
573
|
-
|
574
|
-
|
572
|
+
assert_that { Assert.stub(subject, :withargs).with{ } }.does_not_raise
|
573
|
+
assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.does_not_raise
|
575
574
|
|
576
|
-
|
577
|
-
|
575
|
+
assert_that { Assert.stub(subject, :minargs).with{ } }.does_not_raise
|
576
|
+
assert_that { Assert.stub(subject, :minargs).with(1){ } }.does_not_raise
|
578
577
|
|
579
|
-
|
578
|
+
assert_that { Assert.stub(subject, :withblock).with(1){ } }.does_not_raise
|
580
579
|
end
|
581
580
|
|
582
581
|
should "allow calling methods with invalid arity" do
|
583
|
-
|
582
|
+
assert_that { subject.noargs(1) }.does_not_raise
|
584
583
|
|
585
|
-
|
586
|
-
|
584
|
+
assert_that { subject.withargs }.does_not_raise
|
585
|
+
assert_that { subject.withargs(1, 2) }.does_not_raise
|
587
586
|
|
588
|
-
|
589
|
-
|
587
|
+
assert_that { subject.minargs }.does_not_raise
|
588
|
+
assert_that { subject.minargs(1) }.does_not_raise
|
590
589
|
|
591
|
-
|
590
|
+
assert_that { subject.withblock(1) }.does_not_raise
|
592
591
|
end
|
593
592
|
end
|
594
593
|
|
595
594
|
class DelegateInstanceTests < SystemTests
|
596
595
|
desc "an instance that delegates another object"
|
596
|
+
subject { DelegateClass.new }
|
597
|
+
|
597
598
|
setup do
|
598
|
-
|
599
|
-
Assert.stub(
|
600
|
-
Assert.stub(@instance, :noargs).with{ "none" }
|
599
|
+
Assert.stub(subject, :noargs){ "default" }
|
600
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
601
601
|
|
602
|
-
Assert.stub(
|
603
|
-
Assert.stub(
|
602
|
+
Assert.stub(subject, :withargs){ "default" }
|
603
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
604
604
|
|
605
|
-
Assert.stub(
|
606
|
-
Assert.stub(
|
605
|
+
Assert.stub(subject, :anyargs){ "default" }
|
606
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
607
607
|
|
608
|
-
Assert.stub(
|
609
|
-
Assert.stub(
|
610
|
-
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" }
|
611
611
|
|
612
|
-
Assert.stub(
|
612
|
+
Assert.stub(subject, :withblock){ "default" }
|
613
613
|
end
|
614
|
-
subject{ @instance }
|
615
614
|
|
616
615
|
should "allow stubbing a method that doesn't take args" do
|
617
|
-
|
616
|
+
assert_that(subject.noargs).equals("none")
|
618
617
|
end
|
619
618
|
|
620
619
|
should "allow stubbing a method that takes args" do
|
621
|
-
|
622
|
-
|
620
|
+
assert_that(subject.withargs(1)).equals("one")
|
621
|
+
assert_that(subject.withargs(2)).equals("default")
|
623
622
|
end
|
624
623
|
|
625
624
|
should "allow stubbing a method that takes any args" do
|
626
|
-
|
627
|
-
|
628
|
-
|
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")
|
629
628
|
end
|
630
629
|
|
631
630
|
should "allow stubbing a method that takes a minimum number of args" do
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
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")
|
636
635
|
end
|
637
636
|
|
638
637
|
should "allow stubbing a method that takes a block" do
|
639
|
-
|
640
|
-
|
638
|
+
assert_that(subject.withblock).equals("default")
|
639
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
641
640
|
end
|
642
641
|
|
643
642
|
should "allow stubbing methods with invalid arity" do
|
644
|
-
|
643
|
+
assert_that { Assert.stub(subject, :noargs).with(1){ } }.does_not_raise
|
645
644
|
|
646
|
-
|
647
|
-
|
645
|
+
assert_that { Assert.stub(subject, :withargs).with{ } }.does_not_raise
|
646
|
+
assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.does_not_raise
|
648
647
|
|
649
|
-
|
650
|
-
|
648
|
+
assert_that { Assert.stub(subject, :minargs).with{ } }.does_not_raise
|
649
|
+
assert_that { Assert.stub(subject, :minargs).with(1){ } }.does_not_raise
|
651
650
|
|
652
|
-
|
651
|
+
assert_that { Assert.stub(subject, :withblock).with(1){ } }.does_not_raise
|
653
652
|
end
|
654
653
|
|
655
654
|
should "allow calling methods with invalid arity" do
|
656
|
-
|
655
|
+
assert_that { subject.noargs(1) }.does_not_raise
|
657
656
|
|
658
|
-
|
659
|
-
|
657
|
+
assert_that { subject.withargs }.does_not_raise
|
658
|
+
assert_that { subject.withargs(1, 2) }.does_not_raise
|
660
659
|
|
661
|
-
|
662
|
-
|
660
|
+
assert_that { subject.minargs }.does_not_raise
|
661
|
+
assert_that { subject.minargs(1) }.does_not_raise
|
663
662
|
|
664
|
-
|
663
|
+
assert_that { subject.withblock(1) }.does_not_raise
|
665
664
|
end
|
666
665
|
end
|
667
666
|
|
668
667
|
class ParentAndChildClassTests < SystemTests
|
669
668
|
desc "for a parent method stubbed on both the parent and child"
|
670
669
|
setup do
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
Assert.stub(@parent_class, :new){ "parent" }
|
675
|
-
Assert.stub(@child_class, :new){ "child" }
|
670
|
+
Assert.stub(parent_class, :new){ "parent" }
|
671
|
+
Assert.stub(child_class, :new){ "child" }
|
676
672
|
end
|
677
673
|
|
674
|
+
let(:parent_class) { Class.new }
|
675
|
+
let(:child_class) { Class.new(parent_class) }
|
676
|
+
|
678
677
|
should "allow stubbing the methods individually" do
|
679
|
-
|
680
|
-
|
678
|
+
assert_that(parent_class.new).equals("parent")
|
679
|
+
assert_that(child_class.new).equals("child")
|
681
680
|
end
|
682
681
|
end
|
683
682
|
|