assert 2.19.2 → 2.19.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assert.gemspec +10 -7
- data/lib/assert.rb +18 -6
- data/lib/assert/actual_value.rb +8 -6
- data/lib/assert/assert_runner.rb +36 -17
- data/lib/assert/assertions.rb +83 -50
- data/lib/assert/cli.rb +17 -66
- data/lib/assert/clirb.rb +55 -0
- data/lib/assert/config.rb +7 -7
- data/lib/assert/config_helpers.rb +55 -22
- data/lib/assert/context.rb +14 -18
- data/lib/assert/context/let_dsl.rb +5 -2
- data/lib/assert/context/setup_dsl.rb +21 -16
- data/lib/assert/context/subject_dsl.rb +6 -7
- data/lib/assert/context/suite_dsl.rb +2 -1
- data/lib/assert/context/test_dsl.rb +55 -19
- data/lib/assert/default_suite.rb +25 -15
- data/lib/assert/default_view.rb +47 -30
- data/lib/assert/file_line.rb +6 -6
- data/lib/assert/macro.rb +1 -1
- data/lib/assert/macros/methods.rb +71 -45
- data/lib/assert/result.rb +111 -62
- data/lib/assert/runner.rb +68 -51
- data/lib/assert/stub.rb +4 -4
- data/lib/assert/suite.rb +67 -28
- data/lib/assert/test.rb +40 -35
- data/lib/assert/utils.rb +19 -10
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +44 -18
- data/lib/assert/view_helpers.rb +100 -92
- data/test/helper.rb +3 -1
- data/test/support/factory.rb +38 -21
- data/test/system/stub_tests.rb +180 -144
- data/test/system/test_tests.rb +86 -60
- data/test/unit/actual_value_tests.rb +69 -50
- data/test/unit/assert_tests.rb +39 -22
- data/test/unit/assertions/assert_block_tests.rb +10 -10
- data/test/unit/assertions/assert_changes_tests.rb +25 -21
- data/test/unit/assertions/assert_empty_tests.rb +14 -12
- data/test/unit/assertions/assert_equal_tests.rb +26 -26
- data/test/unit/assertions/assert_file_exists_tests.rb +15 -13
- data/test/unit/assertions/assert_includes_tests.rb +10 -10
- data/test/unit/assertions/assert_instance_of_tests.rb +14 -14
- data/test/unit/assertions/assert_is_a_tests.rb +128 -0
- data/test/unit/assertions/assert_match_tests.rb +10 -10
- data/test/unit/assertions/assert_nil_tests.rb +16 -12
- data/test/unit/assertions/assert_raises_tests.rb +27 -20
- data/test/unit/assertions/assert_respond_to_tests.rb +10 -10
- data/test/unit/assertions/assert_same_tests.rb +24 -24
- data/test/unit/assertions/assert_true_false_tests.rb +32 -24
- data/test/unit/assertions_tests.rb +14 -9
- data/test/unit/config_helpers_tests.rb +15 -10
- data/test/unit/config_tests.rb +10 -9
- data/test/unit/context/setup_dsl_tests.rb +24 -14
- data/test/unit/context/subject_dsl_tests.rb +3 -3
- data/test/unit/context/suite_dsl_tests.rb +4 -4
- data/test/unit/context/test_dsl_tests.rb +37 -17
- data/test/unit/context_info_tests.rb +4 -4
- data/test/unit/context_tests.rb +110 -54
- data/test/unit/default_suite_tests.rb +10 -6
- data/test/unit/factory_tests.rb +2 -2
- data/test/unit/file_line_tests.rb +7 -7
- data/test/unit/macro_tests.rb +11 -11
- data/test/unit/result_tests.rb +47 -41
- data/test/unit/runner_tests.rb +29 -16
- data/test/unit/suite_tests.rb +37 -15
- data/test/unit/test_tests.rb +63 -50
- data/test/unit/utils_tests.rb +48 -35
- data/test/unit/view_helpers_tests.rb +21 -14
- data/test/unit/view_tests.rb +5 -5
- metadata +26 -11
- data/test/unit/assertions/assert_kind_of_tests.rb +0 -68
data/lib/assert/view_helpers.rb
CHANGED
@@ -16,7 +16,7 @@ module Assert
|
|
16
16
|
def option(name, *default_vals)
|
17
17
|
default = default_vals.size > 1 ? default_vals : default_vals.first
|
18
18
|
define_method(name) do |*args|
|
19
|
-
|
19
|
+
unless (value = args.size > 1 ? args : args.first).nil?
|
20
20
|
instance_variable_set("@#{name}", value)
|
21
21
|
end
|
22
22
|
(val = instance_variable_get("@#{name}")).nil? ? default : val
|
@@ -38,11 +38,11 @@ module Assert
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def tests_to_run_count_statement
|
41
|
-
"#{
|
41
|
+
"#{tests_to_run_count} test#{"s" if tests_to_run_count != 1}"
|
42
42
|
end
|
43
43
|
|
44
44
|
def result_count_statement
|
45
|
-
"#{
|
45
|
+
"#{result_count} result#{"s" if result_count != 1}"
|
46
46
|
end
|
47
47
|
|
48
48
|
# generate a comma-seperated sentence fragment given a list of items
|
@@ -56,9 +56,9 @@ module Assert
|
|
56
56
|
|
57
57
|
# generate an appropriate result summary msg for all tests passing
|
58
58
|
def all_pass_result_summary_msg
|
59
|
-
if
|
59
|
+
if result_count < 1
|
60
60
|
"uhh..."
|
61
|
-
elsif
|
61
|
+
elsif result_count == 1
|
62
62
|
"pass"
|
63
63
|
else
|
64
64
|
"all pass"
|
@@ -67,112 +67,120 @@ module Assert
|
|
67
67
|
|
68
68
|
# print a result summary message for a given result type
|
69
69
|
def result_summary_msg(result_type)
|
70
|
-
if result_type == :pass &&
|
71
|
-
|
70
|
+
if result_type == :pass && all_pass?
|
71
|
+
all_pass_result_summary_msg
|
72
72
|
else
|
73
|
-
"#{
|
73
|
+
"#{send("#{result_type}_result_count")} #{result_type}"
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
# generate a sentence fragment describing the breakdown of test results
|
78
|
-
# if a block is given, yield each msg in the breakdown for custom
|
78
|
+
# if a block is given, yield each msg in the breakdown for custom
|
79
|
+
# formatting.
|
79
80
|
def results_summary_sentence
|
80
|
-
summaries =
|
81
|
-
summary_msg =
|
81
|
+
summaries = ocurring_result_types.map do |result_type|
|
82
|
+
summary_msg = result_summary_msg(result_type)
|
82
83
|
block_given? ? yield(summary_msg, result_type) : summary_msg
|
83
84
|
end
|
84
|
-
|
85
|
+
to_sentence(summaries)
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
88
89
|
module Ansi
|
89
|
-
# Table of supported styles/codes
|
90
|
+
# Table of supported styles/codes
|
91
|
+
# (http://en.wikipedia.org/wiki/ANSI_escape_code).
|
90
92
|
CODES = {
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
98
|
-
:
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
102
|
-
:
|
103
|
-
:
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
110
|
-
:
|
111
|
-
:
|
112
|
-
:
|
113
|
-
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
117
|
-
:
|
118
|
-
:
|
119
|
-
:
|
120
|
-
:
|
121
|
-
:
|
122
|
-
:
|
123
|
-
:
|
124
|
-
:
|
125
|
-
:
|
126
|
-
:
|
127
|
-
:
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
135
|
-
:
|
136
|
-
:
|
137
|
-
:
|
138
|
-
:
|
139
|
-
:
|
140
|
-
:
|
141
|
-
:
|
142
|
-
|
143
|
-
:
|
144
|
-
:
|
145
|
-
:
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
149
|
-
:
|
150
|
-
:
|
151
|
-
|
152
|
-
:
|
153
|
-
:
|
154
|
-
:
|
155
|
-
:
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:
|
159
|
-
:
|
160
|
-
|
161
|
-
:
|
162
|
-
:
|
163
|
-
:
|
164
|
-
:
|
165
|
-
:
|
166
|
-
:
|
93
|
+
clear: 0,
|
94
|
+
reset: 0,
|
95
|
+
bright: 1,
|
96
|
+
bold: 1,
|
97
|
+
faint: 2,
|
98
|
+
dark: 2,
|
99
|
+
italic: 3,
|
100
|
+
underline: 4,
|
101
|
+
underscore: 4,
|
102
|
+
blink: 5,
|
103
|
+
slow_blink: 5,
|
104
|
+
rapid: 6,
|
105
|
+
rapid_blink: 6,
|
106
|
+
invert: 7,
|
107
|
+
inverse: 7,
|
108
|
+
reverse: 7,
|
109
|
+
negative: 7,
|
110
|
+
swap: 7,
|
111
|
+
conceal: 8,
|
112
|
+
concealed: 8,
|
113
|
+
hide: 9,
|
114
|
+
strike: 9,
|
115
|
+
|
116
|
+
default_font: 10,
|
117
|
+
font_default: 10,
|
118
|
+
font0: 10,
|
119
|
+
font1: 11,
|
120
|
+
font2: 12,
|
121
|
+
font3: 13,
|
122
|
+
font4: 14,
|
123
|
+
font5: 15,
|
124
|
+
font6: 16,
|
125
|
+
font7: 17,
|
126
|
+
font8: 18,
|
127
|
+
font9: 19,
|
128
|
+
fraktur: 20,
|
129
|
+
bright_off: 21,
|
130
|
+
bold_off: 21,
|
131
|
+
double_underline: 21,
|
132
|
+
clean: 22,
|
133
|
+
italic_off: 23,
|
134
|
+
fraktur_off: 23,
|
135
|
+
underline_off: 24,
|
136
|
+
blink_off: 25,
|
137
|
+
inverse_off: 26,
|
138
|
+
positive: 26,
|
139
|
+
conceal_off: 27,
|
140
|
+
show: 27,
|
141
|
+
reveal: 27,
|
142
|
+
crossed_off: 29,
|
143
|
+
crossed_out_off: 29,
|
144
|
+
|
145
|
+
black: 30,
|
146
|
+
red: 31,
|
147
|
+
green: 32,
|
148
|
+
yellow: 33,
|
149
|
+
blue: 34,
|
150
|
+
magenta: 35,
|
151
|
+
cyan: 36,
|
152
|
+
white: 37,
|
153
|
+
|
154
|
+
on_black: 40,
|
155
|
+
on_red: 41,
|
156
|
+
on_green: 42,
|
157
|
+
on_yellow: 43,
|
158
|
+
on_blue: 44,
|
159
|
+
on_magenta: 45,
|
160
|
+
on_cyan: 46,
|
161
|
+
on_white: 47,
|
162
|
+
|
163
|
+
frame: 51,
|
164
|
+
encircle: 52,
|
165
|
+
overline: 53,
|
166
|
+
frame_off: 54,
|
167
|
+
encircle_off: 54,
|
168
|
+
overline_off: 55,
|
167
169
|
}
|
168
170
|
|
169
171
|
def self.code_for(*style_names)
|
170
|
-
style_names
|
172
|
+
style_names
|
173
|
+
.map{ |n| "\e[#{CODES[n]}m" if CODES.key?(n) }
|
174
|
+
.compact
|
175
|
+
.join("")
|
171
176
|
end
|
172
177
|
|
173
178
|
def ansi_styled_msg(msg, result_type)
|
174
|
-
return msg if !
|
175
|
-
code =
|
179
|
+
return msg if !is_tty? || !styled
|
180
|
+
code =
|
181
|
+
Assert::ViewHelpers::Ansi.code_for(
|
182
|
+
*send("#{result_type}_styles"),
|
183
|
+
)
|
176
184
|
return msg if code.empty?
|
177
185
|
code + msg + Assert::ViewHelpers::Ansi.code_for(:reset)
|
178
186
|
end
|
data/test/helper.rb
CHANGED
@@ -16,12 +16,13 @@ module Assert::Test::TestHelpers
|
|
16
16
|
receiver.class_eval do
|
17
17
|
setup do
|
18
18
|
@test_run_results = []
|
19
|
-
@run_callback = proc
|
19
|
+
@run_callback = proc{ |result| @test_run_results << result }
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
25
26
|
def test_run_callback
|
26
27
|
@run_callback
|
27
28
|
end
|
@@ -42,5 +43,6 @@ module Assert::Test::TestHelpers
|
|
42
43
|
def last_test_run_result
|
43
44
|
@test_run_results.last
|
44
45
|
end
|
46
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
45
47
|
end
|
46
48
|
end
|
data/test/support/factory.rb
CHANGED
@@ -10,11 +10,17 @@ module Factory
|
|
10
10
|
extend Assert::Factory
|
11
11
|
|
12
12
|
def self.context_info_called_from
|
13
|
-
File.expand_path(
|
13
|
+
File.expand_path(
|
14
|
+
"#{Factory.path}_tests.rb:#{Factory.integer}",
|
15
|
+
Dir.pwd,
|
16
|
+
)
|
14
17
|
end
|
15
18
|
|
16
19
|
def self.context_info(context_klass = nil)
|
17
|
-
Assert::ContextInfo.new(
|
20
|
+
Assert::ContextInfo.new(
|
21
|
+
context_klass || context_class,
|
22
|
+
context_info_called_from,
|
23
|
+
)
|
18
24
|
end
|
19
25
|
|
20
26
|
# Generate an anonymous `Context` inherited from `Assert::Context` by default.
|
@@ -24,9 +30,8 @@ module Factory
|
|
24
30
|
klass = Class.new(inherit_from || Assert::Context, &block)
|
25
31
|
default = const_name = "FactoryAssertContext"
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
33
|
+
const_name =
|
34
|
+
"#{default}#{rand(Time.now.to_i)}" while Object.const_defined?(const_name)
|
30
35
|
Object.const_set(const_name, klass)
|
31
36
|
klass
|
32
37
|
end
|
@@ -35,9 +40,9 @@ module Factory
|
|
35
40
|
|
36
41
|
def self.test(*args, &block)
|
37
42
|
config, context_info, name = [
|
38
|
-
args.last.
|
39
|
-
args.last.
|
40
|
-
args.last.
|
43
|
+
args.last.is_a?(Assert::Config) ? args.pop : modes_off_config,
|
44
|
+
args.last.is_a?(Assert::ContextInfo) ? args.pop : self.context_info,
|
45
|
+
args.last.is_a?(::String) ? args.pop : "a test",
|
41
46
|
]
|
42
47
|
Assert::Test.for_block(name, context_info, config, &block)
|
43
48
|
end
|
@@ -45,15 +50,27 @@ module Factory
|
|
45
50
|
# Generate results for use in testing.
|
46
51
|
|
47
52
|
def self.pass_result(msg = nil)
|
48
|
-
Assert::Result::Pass.for_test(
|
53
|
+
Assert::Result::Pass.for_test(
|
54
|
+
Factory.test(Factory.string),
|
55
|
+
msg || Factory.string,
|
56
|
+
[],
|
57
|
+
)
|
49
58
|
end
|
50
59
|
|
51
60
|
def self.ignore_result(msg = nil)
|
52
|
-
Assert::Result::Ignore.for_test(
|
61
|
+
Assert::Result::Ignore.for_test(
|
62
|
+
Factory.test(Factory.string),
|
63
|
+
msg || Factory.string,
|
64
|
+
[],
|
65
|
+
)
|
53
66
|
end
|
54
67
|
|
55
68
|
def self.fail_result(msg = nil)
|
56
|
-
Assert::Result::Fail.for_test(
|
69
|
+
Assert::Result::Fail.for_test(
|
70
|
+
Factory.test(Factory.string),
|
71
|
+
msg || Factory.string,
|
72
|
+
[],
|
73
|
+
)
|
57
74
|
end
|
58
75
|
|
59
76
|
def self.skip_result(exception = nil)
|
@@ -68,23 +85,23 @@ module Factory
|
|
68
85
|
|
69
86
|
def self.modes_off_config
|
70
87
|
Assert::Config.new({
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:
|
75
|
-
:
|
88
|
+
capture_output: false,
|
89
|
+
halt_on_fail: false,
|
90
|
+
changed_only: false,
|
91
|
+
pp_objects: false,
|
92
|
+
debug: false,
|
76
93
|
})
|
77
94
|
end
|
78
95
|
|
79
96
|
def self.modes_off_suite
|
80
|
-
Assert::DefaultSuite.new(
|
97
|
+
Assert::DefaultSuite.new(modes_off_config)
|
81
98
|
end
|
82
99
|
|
83
100
|
def self.modes_off_context_class(*args, &block)
|
84
|
-
suite_obj =
|
85
|
-
|
101
|
+
suite_obj = modes_off_suite
|
102
|
+
context_class(*args) do
|
86
103
|
suite(suite_obj)
|
87
|
-
instance_eval(&block)
|
104
|
+
instance_eval(&block) unless block.nil?
|
88
105
|
end
|
89
106
|
end
|
90
107
|
|
@@ -93,7 +110,7 @@ module Factory
|
|
93
110
|
Factory.modes_off_context_class.new(
|
94
111
|
test,
|
95
112
|
test.config,
|
96
|
-
result_block || proc
|
113
|
+
result_block || proc{ |r| },
|
97
114
|
)
|
98
115
|
end
|
99
116
|
|
data/test/system/stub_tests.rb
CHANGED
@@ -10,7 +10,7 @@ class Assert::Stub
|
|
10
10
|
|
11
11
|
class InstanceTests < SystemTests
|
12
12
|
desc "for instance methods"
|
13
|
-
subject
|
13
|
+
subject{ TestClass.new }
|
14
14
|
|
15
15
|
setup do
|
16
16
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -56,33 +56,33 @@ class Assert::Stub
|
|
56
56
|
end
|
57
57
|
|
58
58
|
should "not allow stubbing methods with invalid arity" do
|
59
|
-
assert_that
|
59
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
60
60
|
|
61
|
-
assert_that
|
62
|
-
assert_that
|
61
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
62
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
63
63
|
|
64
|
-
assert_that
|
65
|
-
assert_that
|
64
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
65
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
66
66
|
|
67
|
-
assert_that
|
67
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
68
68
|
end
|
69
69
|
|
70
70
|
should "not allow calling methods with invalid arity" do
|
71
|
-
assert_that
|
71
|
+
assert_that{ subject.noargs(1) }.raises
|
72
72
|
|
73
|
-
assert_that
|
74
|
-
assert_that
|
73
|
+
assert_that{ subject.withargs }.raises
|
74
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
75
75
|
|
76
|
-
assert_that
|
77
|
-
assert_that
|
76
|
+
assert_that{ subject.minargs }.raises
|
77
|
+
assert_that{ subject.minargs(1) }.raises
|
78
78
|
|
79
|
-
assert_that
|
79
|
+
assert_that{ subject.withblock(1) }.raises
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
class ClassTests < SystemTests
|
84
84
|
desc "for singleton methods on a class"
|
85
|
-
subject
|
85
|
+
subject{ TestClass }
|
86
86
|
|
87
87
|
setup do
|
88
88
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -129,33 +129,33 @@ class Assert::Stub
|
|
129
129
|
end
|
130
130
|
|
131
131
|
should "not allow stubbing methods with invalid arity" do
|
132
|
-
assert_that
|
132
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
133
133
|
|
134
|
-
assert_that
|
135
|
-
assert_that
|
134
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
135
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
136
136
|
|
137
|
-
assert_that
|
138
|
-
assert_that
|
137
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
138
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
139
139
|
|
140
|
-
assert_that
|
140
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
141
141
|
end
|
142
142
|
|
143
143
|
should "not allow calling methods with invalid arity" do
|
144
|
-
assert_that
|
144
|
+
assert_that{ subject.noargs(1) }.raises
|
145
145
|
|
146
|
-
assert_that
|
147
|
-
assert_that
|
146
|
+
assert_that{ subject.withargs }.raises
|
147
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
148
148
|
|
149
|
-
assert_that
|
150
|
-
assert_that
|
149
|
+
assert_that{ subject.minargs }.raises
|
150
|
+
assert_that{ subject.minargs(1) }.raises
|
151
151
|
|
152
|
-
assert_that
|
152
|
+
assert_that{ subject.withblock(1) }.raises
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
156
|
class ModuleTests < SystemTests
|
157
157
|
desc "for singleton methods on a module"
|
158
|
-
subject
|
158
|
+
subject{ TestModule }
|
159
159
|
|
160
160
|
setup do
|
161
161
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -202,33 +202,33 @@ class Assert::Stub
|
|
202
202
|
end
|
203
203
|
|
204
204
|
should "not allow stubbing methods with invalid arity" do
|
205
|
-
assert_that
|
205
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
206
206
|
|
207
|
-
assert_that
|
208
|
-
assert_that
|
207
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
208
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
209
209
|
|
210
|
-
assert_that
|
211
|
-
assert_that
|
210
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
211
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
212
212
|
|
213
|
-
assert_that
|
213
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
214
214
|
end
|
215
215
|
|
216
216
|
should "not allow calling methods with invalid arity" do
|
217
|
-
assert_that
|
217
|
+
assert_that{ subject.noargs(1) }.raises
|
218
218
|
|
219
|
-
assert_that
|
220
|
-
assert_that
|
219
|
+
assert_that{ subject.withargs }.raises
|
220
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
221
221
|
|
222
|
-
assert_that
|
223
|
-
assert_that
|
222
|
+
assert_that{ subject.minargs }.raises
|
223
|
+
assert_that{ subject.minargs(1) }.raises
|
224
224
|
|
225
|
-
assert_that
|
225
|
+
assert_that{ subject.withblock(1) }.raises
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
229
229
|
class ExtendedTests < SystemTests
|
230
230
|
desc "for extended methods"
|
231
|
-
subject
|
231
|
+
subject{ Class.new{ extend TestMixin } }
|
232
232
|
|
233
233
|
setup do
|
234
234
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -275,35 +275,35 @@ class Assert::Stub
|
|
275
275
|
end
|
276
276
|
|
277
277
|
should "not allow stubbing methods with invalid arity" do
|
278
|
-
assert_that
|
278
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
279
279
|
|
280
|
-
assert_that
|
281
|
-
assert_that
|
280
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
281
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
282
282
|
|
283
|
-
assert_that
|
284
|
-
assert_that
|
283
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
284
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
285
285
|
|
286
|
-
assert_that
|
286
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
287
287
|
end
|
288
288
|
|
289
289
|
should "not allow calling methods with invalid arity" do
|
290
|
-
assert_that
|
290
|
+
assert_that{ subject.noargs(1) }.raises
|
291
291
|
|
292
|
-
assert_that
|
293
|
-
assert_that
|
292
|
+
assert_that{ subject.withargs }.raises
|
293
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
294
294
|
|
295
|
-
assert_that
|
296
|
-
assert_that
|
295
|
+
assert_that{ subject.minargs }.raises
|
296
|
+
assert_that{ subject.minargs(1) }.raises
|
297
297
|
|
298
|
-
assert_that
|
298
|
+
assert_that{ subject.withblock(1) }.raises
|
299
299
|
end
|
300
300
|
end
|
301
301
|
|
302
302
|
class IncludedTests < SystemTests
|
303
303
|
desc "for an included method"
|
304
|
-
subject
|
305
|
-
Class.new
|
306
|
-
|
304
|
+
subject do
|
305
|
+
Class.new{ include TestMixin }.new
|
306
|
+
end
|
307
307
|
|
308
308
|
setup do
|
309
309
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -350,33 +350,33 @@ class Assert::Stub
|
|
350
350
|
end
|
351
351
|
|
352
352
|
should "not allow stubbing methods with invalid arity" do
|
353
|
-
assert_that
|
353
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
354
354
|
|
355
|
-
assert_that
|
356
|
-
assert_that
|
355
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
356
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
357
357
|
|
358
|
-
assert_that
|
359
|
-
assert_that
|
358
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
359
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
360
360
|
|
361
|
-
assert_that
|
361
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
362
362
|
end
|
363
363
|
|
364
364
|
should "not allow calling methods with invalid arity" do
|
365
|
-
assert_that
|
365
|
+
assert_that{ subject.noargs(1) }.raises
|
366
366
|
|
367
|
-
assert_that
|
368
|
-
assert_that
|
367
|
+
assert_that{ subject.withargs }.raises
|
368
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
369
369
|
|
370
|
-
assert_that
|
371
|
-
assert_that
|
370
|
+
assert_that{ subject.minargs }.raises
|
371
|
+
assert_that{ subject.minargs(1) }.raises
|
372
372
|
|
373
|
-
assert_that
|
373
|
+
assert_that{ subject.withblock(1) }.raises
|
374
374
|
end
|
375
375
|
end
|
376
376
|
|
377
377
|
class InheritedClassTests < SystemTests
|
378
378
|
desc "for an inherited class method"
|
379
|
-
subject
|
379
|
+
subject{ Class.new(TestClass) }
|
380
380
|
|
381
381
|
setup do
|
382
382
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -423,33 +423,33 @@ class Assert::Stub
|
|
423
423
|
end
|
424
424
|
|
425
425
|
should "not allow stubbing methods with invalid arity" do
|
426
|
-
assert_that
|
426
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
427
427
|
|
428
|
-
assert_that
|
429
|
-
assert_that
|
428
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
429
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
430
430
|
|
431
|
-
assert_that
|
432
|
-
assert_that
|
431
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
432
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
433
433
|
|
434
|
-
assert_that
|
434
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
435
435
|
end
|
436
436
|
|
437
437
|
should "not allow calling methods with invalid arity" do
|
438
|
-
assert_that
|
438
|
+
assert_that{ subject.noargs(1) }.raises
|
439
439
|
|
440
|
-
assert_that
|
441
|
-
assert_that
|
440
|
+
assert_that{ subject.withargs }.raises
|
441
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
442
442
|
|
443
|
-
assert_that
|
444
|
-
assert_that
|
443
|
+
assert_that{ subject.minargs }.raises
|
444
|
+
assert_that{ subject.minargs(1) }.raises
|
445
445
|
|
446
|
-
assert_that
|
446
|
+
assert_that{ subject.withblock(1) }.raises
|
447
447
|
end
|
448
448
|
end
|
449
449
|
|
450
450
|
class InheritedInstanceTests < SystemTests
|
451
451
|
desc "for an inherited instance method"
|
452
|
-
subject
|
452
|
+
subject{ Class.new(TestClass).new }
|
453
453
|
|
454
454
|
setup do
|
455
455
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -496,33 +496,33 @@ class Assert::Stub
|
|
496
496
|
end
|
497
497
|
|
498
498
|
should "not allow stubbing methods with invalid arity" do
|
499
|
-
assert_that
|
499
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
500
500
|
|
501
|
-
assert_that
|
502
|
-
assert_that
|
501
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
502
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
503
503
|
|
504
|
-
assert_that
|
505
|
-
assert_that
|
504
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
505
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
506
506
|
|
507
|
-
assert_that
|
507
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
508
508
|
end
|
509
509
|
|
510
510
|
should "not allow calling methods with invalid arity" do
|
511
|
-
assert_that
|
511
|
+
assert_that{ subject.noargs(1) }.raises
|
512
512
|
|
513
|
-
assert_that
|
514
|
-
assert_that
|
513
|
+
assert_that{ subject.withargs }.raises
|
514
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
515
515
|
|
516
|
-
assert_that
|
517
|
-
assert_that
|
516
|
+
assert_that{ subject.minargs }.raises
|
517
|
+
assert_that{ subject.minargs(1) }.raises
|
518
518
|
|
519
|
-
assert_that
|
519
|
+
assert_that{ subject.withblock(1) }.raises
|
520
520
|
end
|
521
521
|
end
|
522
522
|
|
523
523
|
class DelegateClassTests < SystemTests
|
524
524
|
desc "a class that delegates another object"
|
525
|
-
subject
|
525
|
+
subject{ DelegateClass }
|
526
526
|
|
527
527
|
setup do
|
528
528
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -569,33 +569,33 @@ class Assert::Stub
|
|
569
569
|
end
|
570
570
|
|
571
571
|
should "allow stubbing methods with invalid arity" do
|
572
|
-
assert_that
|
572
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.does_not_raise
|
573
573
|
|
574
|
-
assert_that
|
575
|
-
assert_that
|
574
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.does_not_raise
|
575
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.does_not_raise
|
576
576
|
|
577
|
-
assert_that
|
578
|
-
assert_that
|
577
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.does_not_raise
|
578
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.does_not_raise
|
579
579
|
|
580
|
-
assert_that
|
580
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.does_not_raise
|
581
581
|
end
|
582
582
|
|
583
583
|
should "allow calling methods with invalid arity" do
|
584
|
-
assert_that
|
584
|
+
assert_that{ subject.noargs(1) }.does_not_raise
|
585
585
|
|
586
|
-
assert_that
|
587
|
-
assert_that
|
586
|
+
assert_that{ subject.withargs }.does_not_raise
|
587
|
+
assert_that{ subject.withargs(1, 2) }.does_not_raise
|
588
588
|
|
589
|
-
assert_that
|
590
|
-
assert_that
|
589
|
+
assert_that{ subject.minargs }.does_not_raise
|
590
|
+
assert_that{ subject.minargs(1) }.does_not_raise
|
591
591
|
|
592
|
-
assert_that
|
592
|
+
assert_that{ subject.withblock(1) }.does_not_raise
|
593
593
|
end
|
594
594
|
end
|
595
595
|
|
596
596
|
class DelegateInstanceTests < SystemTests
|
597
597
|
desc "an instance that delegates another object"
|
598
|
-
subject
|
598
|
+
subject{ DelegateClass.new }
|
599
599
|
|
600
600
|
setup do
|
601
601
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -642,27 +642,27 @@ class Assert::Stub
|
|
642
642
|
end
|
643
643
|
|
644
644
|
should "allow stubbing methods with invalid arity" do
|
645
|
-
assert_that
|
645
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.does_not_raise
|
646
646
|
|
647
|
-
assert_that
|
648
|
-
assert_that
|
647
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.does_not_raise
|
648
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.does_not_raise
|
649
649
|
|
650
|
-
assert_that
|
651
|
-
assert_that
|
650
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.does_not_raise
|
651
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.does_not_raise
|
652
652
|
|
653
|
-
assert_that
|
653
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.does_not_raise
|
654
654
|
end
|
655
655
|
|
656
656
|
should "allow calling methods with invalid arity" do
|
657
|
-
assert_that
|
657
|
+
assert_that{ subject.noargs(1) }.does_not_raise
|
658
658
|
|
659
|
-
assert_that
|
660
|
-
assert_that
|
659
|
+
assert_that{ subject.withargs }.does_not_raise
|
660
|
+
assert_that{ subject.withargs(1, 2) }.does_not_raise
|
661
661
|
|
662
|
-
assert_that
|
663
|
-
assert_that
|
662
|
+
assert_that{ subject.minargs }.does_not_raise
|
663
|
+
assert_that{ subject.minargs(1) }.does_not_raise
|
664
664
|
|
665
|
-
assert_that
|
665
|
+
assert_that{ subject.withblock(1) }.does_not_raise
|
666
666
|
end
|
667
667
|
end
|
668
668
|
|
@@ -673,8 +673,8 @@ class Assert::Stub
|
|
673
673
|
Assert.stub(child_class, :new){ "child" }
|
674
674
|
end
|
675
675
|
|
676
|
-
let(:parent_class)
|
677
|
-
let(:child_class)
|
676
|
+
let(:parent_class){ Class.new }
|
677
|
+
let(:child_class){ Class.new(parent_class) }
|
678
678
|
|
679
679
|
should "allow stubbing the methods individually" do
|
680
680
|
assert_that(parent_class.new).equals("parent")
|
@@ -683,37 +683,73 @@ class Assert::Stub
|
|
683
683
|
end
|
684
684
|
|
685
685
|
class TestClass
|
686
|
-
def self.noargs
|
687
|
-
|
688
|
-
|
689
|
-
def self.
|
690
|
-
|
691
|
-
|
692
|
-
def
|
693
|
-
|
694
|
-
|
695
|
-
def minargs(a, b, *args)
|
696
|
-
|
686
|
+
def self.noargs
|
687
|
+
end
|
688
|
+
|
689
|
+
def self.withargs(a)
|
690
|
+
end
|
691
|
+
|
692
|
+
def self.anyargs(*args)
|
693
|
+
end
|
694
|
+
|
695
|
+
def self.minargs(a, b, *args)
|
696
|
+
end
|
697
|
+
|
698
|
+
def self.withblock(&block)
|
699
|
+
end
|
700
|
+
|
701
|
+
def noargs
|
702
|
+
end
|
703
|
+
|
704
|
+
def withargs(a)
|
705
|
+
end
|
706
|
+
|
707
|
+
def anyargs(*args)
|
708
|
+
end
|
709
|
+
|
710
|
+
def minargs(a, b, *args)
|
711
|
+
end
|
712
|
+
|
713
|
+
def withblock(&block)
|
714
|
+
end
|
697
715
|
end
|
698
716
|
|
699
717
|
module TestModule
|
700
|
-
def self.noargs
|
701
|
-
|
702
|
-
|
703
|
-
def self.
|
704
|
-
|
718
|
+
def self.noargs
|
719
|
+
end
|
720
|
+
|
721
|
+
def self.withargs(a)
|
722
|
+
end
|
723
|
+
|
724
|
+
def self.anyargs(*args)
|
725
|
+
end
|
726
|
+
|
727
|
+
def self.minargs(a, b, *args)
|
728
|
+
end
|
729
|
+
|
730
|
+
def self.withblock(&block)
|
731
|
+
end
|
705
732
|
end
|
706
733
|
|
707
734
|
module TestMixin
|
708
|
-
def noargs
|
709
|
-
|
710
|
-
|
711
|
-
def
|
712
|
-
|
735
|
+
def noargs
|
736
|
+
end
|
737
|
+
|
738
|
+
def withargs(a)
|
739
|
+
end
|
740
|
+
|
741
|
+
def anyargs(*args)
|
742
|
+
end
|
743
|
+
|
744
|
+
def minargs(a, b, *args)
|
745
|
+
end
|
746
|
+
|
747
|
+
def withblock(&block)
|
748
|
+
end
|
713
749
|
end
|
714
750
|
|
715
751
|
class DelegateClass
|
716
|
-
def self.
|
752
|
+
def self.respond_to_missing?(*args)
|
717
753
|
TestClass.respond_to?(*args) || super
|
718
754
|
end
|
719
755
|
|
@@ -725,7 +761,7 @@ class Assert::Stub
|
|
725
761
|
@delegate = TestClass.new
|
726
762
|
end
|
727
763
|
|
728
|
-
def
|
764
|
+
def respond_to_missing?(*args)
|
729
765
|
@delegate.respond_to?(*args) || super
|
730
766
|
end
|
731
767
|
|