assert 2.18.0 → 2.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +66 -37
  3. data/assert.gemspec +4 -3
  4. data/lib/assert/actual_value.rb +140 -0
  5. data/lib/assert/assertions.rb +80 -20
  6. data/lib/assert/context.rb +31 -37
  7. data/lib/assert/context/let_dsl.rb +13 -0
  8. data/lib/assert/context/method_missing.rb +19 -0
  9. data/lib/assert/context/subject_dsl.rb +23 -24
  10. data/lib/assert/macros/methods.rb +4 -4
  11. data/lib/assert/result.rb +5 -1
  12. data/lib/assert/stub.rb +16 -0
  13. data/lib/assert/suite.rb +7 -10
  14. data/lib/assert/test.rb +0 -8
  15. data/lib/assert/version.rb +1 -1
  16. data/test/helper.rb +23 -25
  17. data/test/support/factory.rb +15 -0
  18. data/test/system/stub_tests.rb +332 -333
  19. data/test/system/test_tests.rb +99 -109
  20. data/test/unit/actual_value_tests.rb +371 -0
  21. data/test/unit/assert_tests.rb +111 -43
  22. data/test/unit/assertions/assert_block_tests.rb +30 -31
  23. data/test/unit/assertions/assert_changes_tests.rb +97 -0
  24. data/test/unit/assertions/assert_empty_tests.rb +33 -32
  25. data/test/unit/assertions/assert_equal_tests.rb +94 -74
  26. data/test/unit/assertions/assert_file_exists_tests.rb +32 -33
  27. data/test/unit/assertions/assert_includes_tests.rb +38 -37
  28. data/test/unit/assertions/assert_instance_of_tests.rb +34 -33
  29. data/test/unit/assertions/assert_kind_of_tests.rb +34 -33
  30. data/test/unit/assertions/assert_match_tests.rb +34 -33
  31. data/test/unit/assertions/assert_nil_tests.rb +30 -31
  32. data/test/unit/assertions/assert_raises_tests.rb +55 -55
  33. data/test/unit/assertions/assert_respond_to_tests.rb +36 -35
  34. data/test/unit/assertions/assert_same_tests.rb +86 -81
  35. data/test/unit/assertions/assert_true_false_tests.rb +60 -60
  36. data/test/unit/assertions_tests.rb +26 -24
  37. data/test/unit/config_helpers_tests.rb +43 -38
  38. data/test/unit/config_tests.rb +38 -34
  39. data/test/unit/context/let_dsl_tests.rb +10 -0
  40. data/test/unit/context/setup_dsl_tests.rb +70 -81
  41. data/test/unit/context/subject_dsl_tests.rb +15 -43
  42. data/test/unit/context/suite_dsl_tests.rb +15 -16
  43. data/test/unit/context/test_dsl_tests.rb +50 -52
  44. data/test/unit/context_info_tests.rb +23 -15
  45. data/test/unit/context_tests.rb +184 -179
  46. data/test/unit/default_runner_tests.rb +2 -5
  47. data/test/unit/default_suite_tests.rb +57 -53
  48. data/test/unit/factory_tests.rb +5 -3
  49. data/test/unit/file_line_tests.rb +33 -35
  50. data/test/unit/macro_tests.rb +14 -10
  51. data/test/unit/result_tests.rb +159 -183
  52. data/test/unit/runner_tests.rb +64 -64
  53. data/test/unit/suite_tests.rb +56 -59
  54. data/test/unit/test_tests.rb +118 -139
  55. data/test/unit/utils_tests.rb +43 -45
  56. data/test/unit/view_helpers_tests.rb +54 -52
  57. data/test/unit/view_tests.rb +22 -23
  58. metadata +29 -7
@@ -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
- # put all logic in DSL methods to keep context instances pure for running tests
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
- # check if the assertion is a truthy value, if so create a new pass result,
65
- # otherwise create a new fail result with the desc and what failed msg.
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
- # the opposite of assert, check if the assertion is a false value, if so create a new pass
82
- # result, otherwise create a new fail result with the desc and it's what failed msg
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(Assert::Result::Fail, "Pending pass (make it "\
98
- "not pending)")
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
- if subj = self.class.subject
161
- instance_eval(&subj)
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
- module 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(" ")
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
- alias_method :desc, :description
15
- alias_method :describe, :description
13
+ end
14
+ alias_method :desc, :description
15
+ alias_method :describe, :description
16
16
 
17
- def subject(&block)
18
- if block_given?
19
- @subject = block
20
- else
21
- @subject || if superclass.respond_to?(:subject)
22
- superclass.subject
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
- protected
27
+ protected
28
28
 
29
- def descriptions
30
- @descriptions ||= []
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
- assert_respond_to method, subject, msg
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
- assert_respond_to method, subject.class, msg
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
- assert_not_respond_to method, subject, msg
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
- assert_not_respond_to method, subject.class, msg
126
+ assert_that(subject.class).does_not_respond_to(method, msg)
127
127
  end
128
128
  end
129
129
  end
@@ -129,7 +129,11 @@ module Assert::Result
129
129
  end
130
130
 
131
131
  def ==(other_result)
132
- self.type == other_result.type && self.message == other_result.message
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
@@ -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
@@ -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, :test_methods, :setups, :teardowns
16
+ attr_reader :config, :setups, :teardowns
19
17
  attr_accessor :start_time, :end_time
20
18
 
21
19
  def initialize(config)
22
- @config = config
23
- @tests = []
24
- @test_methods = []
25
- @setups = []
26
- @teardowns = []
27
- @start_time = Time.now
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "2.18.0"
2
+ VERSION = "2.19.0"
3
3
  end
@@ -9,38 +9,36 @@ $LOAD_PATH.unshift(ROOT_PATH)
9
9
  require "pry"
10
10
  require "test/support/factory"
11
11
 
12
- class Assert::Test
13
- module TestHelpers
14
- def self.included(receiver)
15
- receiver.class_eval do
16
- setup do
17
- @test_run_results = []
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
- private
21
+ private
23
22
 
24
- def test_run_callback
25
- @run_callback
26
- end
23
+ def test_run_callback
24
+ @run_callback
25
+ end
27
26
 
28
- def test_run_results(type = nil)
29
- return @test_run_results if type.nil?
30
- @test_run_results.select{ |r| r.type == type }
31
- end
27
+ def test_run_results(type = nil)
28
+ return @test_run_results if type.nil?
29
+ @test_run_results.select{ |r| r.type == type }
30
+ end
32
31
 
33
- def test_run_result_count(type = nil)
34
- test_run_results(type).count
35
- end
32
+ def test_run_result_count(type = nil)
33
+ test_run_results(type).count
34
+ end
36
35
 
37
- def test_run_result_messages
38
- @test_run_results.map(&:message)
39
- end
36
+ def test_run_result_messages
37
+ @test_run_results.map(&:message)
38
+ end
40
39
 
41
- def last_test_run_result
42
- @test_run_results.last
43
- end
40
+ def last_test_run_result
41
+ @test_run_results.last
44
42
  end
45
43
  end
46
44
  end
@@ -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
@@ -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
- @instance = TestClass.new
13
- Assert.stub(@instance, :noargs){ "default" }
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(@instance, :withargs){ "default" }
17
- Assert.stub(@instance, :withargs).with(1){ "one" }
17
+ Assert.stub(subject, :withargs){ "default" }
18
+ Assert.stub(subject, :withargs).with(1){ "one" }
18
19
 
19
- Assert.stub(@instance, :anyargs){ "default" }
20
- Assert.stub(@instance, :anyargs).with(1, 2){ "one-two" }
20
+ Assert.stub(subject, :anyargs){ "default" }
21
+ Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
21
22
 
22
- Assert.stub(@instance, :minargs){ "default" }
23
- Assert.stub(@instance, :minargs).with(1, 2){ "one-two" }
24
- Assert.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
23
+ Assert.stub(subject, :minargs){ "default" }
24
+ Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
25
+ Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
25
26
 
26
- Assert.stub(@instance, :withblock){ "default" }
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
- assert_equal "none", subject.noargs
31
+ assert_that(subject.noargs).equals("none")
32
32
  end
33
33
 
34
34
  should "allow stubbing a method that takes args" do
35
- assert_equal "one", subject.withargs(1)
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
- assert_equal "default", subject.anyargs
41
- assert_equal "default", subject.anyargs(1)
42
- assert_equal "one-two", subject.anyargs(1, 2)
39
+ assert_that(subject.anyargs).equals("default")
40
+ assert_that(subject.anyargs(1)).equals("default")
41
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
43
42
  end
44
43
 
45
44
  should "allow stubbing a method that takes a minimum number of args" do
46
- assert_equal "one-two", subject.minargs(1, 2)
47
- assert_equal "one-two-three", subject.minargs(1, 2, 3)
48
- assert_equal "default", subject.minargs(1, 2, 4)
49
- assert_equal "default", subject.minargs(1, 2, 3, 4)
45
+ assert_that(subject.minargs(1, 2)).equals("one-two")
46
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
47
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
48
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
50
49
  end
51
50
 
52
51
  should "allow stubbing a method that takes a block" do
53
- assert_equal "default", subject.withblock
54
- assert_equal "default", subject.withblock{ "my-block" }
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
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
57
+ assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
59
58
 
60
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
61
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
59
+ assert_that { Assert.stub(subject, :withargs).with{ } }.raises
60
+ assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
62
61
 
63
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
64
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
62
+ assert_that { Assert.stub(subject, :minargs).with{ } }.raises
63
+ assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
65
64
 
66
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
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
- assert_raises{ subject.noargs(1) }
69
+ assert_that { subject.noargs(1) }.raises
71
70
 
72
- assert_raises{ subject.withargs }
73
- assert_raises{ subject.withargs(1, 2) }
71
+ assert_that { subject.withargs }.raises
72
+ assert_that { subject.withargs(1, 2) }.raises
74
73
 
75
- assert_raises{ subject.minargs }
76
- assert_raises{ subject.minargs(1) }
74
+ assert_that { subject.minargs }.raises
75
+ assert_that { subject.minargs(1) }.raises
77
76
 
78
- assert_raises{ subject.withblock(1) }
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
- @class = TestClass
86
- Assert.stub(@class, :noargs){ "default" }
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(@class, :withargs){ "default" }
90
- Assert.stub(@class, :withargs).with(1){ "one" }
89
+ Assert.stub(subject, :withargs){ "default" }
90
+ Assert.stub(subject, :withargs).with(1){ "one" }
91
91
 
92
- Assert.stub(@class, :anyargs){ "default" }
93
- Assert.stub(@class, :anyargs).with(1, 2){ "one-two" }
92
+ Assert.stub(subject, :anyargs){ "default" }
93
+ Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
94
94
 
95
- Assert.stub(@class, :minargs){ "default" }
96
- Assert.stub(@class, :minargs).with(1, 2){ "one-two" }
97
- Assert.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
95
+ Assert.stub(subject, :minargs){ "default" }
96
+ Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
97
+ Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
98
98
 
99
- Assert.stub(@class, :withblock){ "default" }
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
- assert_equal "none", subject.noargs
103
+ assert_that(subject.noargs).equals("none")
105
104
  end
106
105
 
107
106
  should "allow stubbing a method that takes args" do
108
- assert_equal "one", subject.withargs(1)
109
- assert_equal "default", subject.withargs(2)
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
- assert_equal "default", subject.anyargs
114
- assert_equal "default", subject.anyargs(1)
115
- assert_equal "one-two", subject.anyargs(1, 2)
112
+ assert_that(subject.anyargs).equals("default")
113
+ assert_that(subject.anyargs(1)).equals("default")
114
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
116
115
  end
117
116
 
118
117
  should "allow stubbing a method that takes a minimum number of args" do
119
- assert_equal "one-two", subject.minargs(1, 2)
120
- assert_equal "one-two-three", subject.minargs(1, 2, 3)
121
- assert_equal "default", subject.minargs(1, 2, 4)
122
- assert_equal "default", subject.minargs(1, 2, 3, 4)
118
+ assert_that(subject.minargs(1, 2)).equals("one-two")
119
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
120
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
121
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
123
122
  end
124
123
 
125
124
  should "allow stubbing a method that takes a block" do
126
- assert_equal "default", subject.withblock
127
- assert_equal "default", subject.withblock{ "my-block" }
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
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
130
+ assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
132
131
 
133
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
134
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
132
+ assert_that { Assert.stub(subject, :withargs).with{ } }.raises
133
+ assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
135
134
 
136
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
137
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
135
+ assert_that { Assert.stub(subject, :minargs).with{ } }.raises
136
+ assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
138
137
 
139
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
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
- assert_raises{ subject.noargs(1) }
142
+ assert_that { subject.noargs(1) }.raises
144
143
 
145
- assert_raises{ subject.withargs }
146
- assert_raises{ subject.withargs(1, 2) }
144
+ assert_that { subject.withargs }.raises
145
+ assert_that { subject.withargs(1, 2) }.raises
147
146
 
148
- assert_raises{ subject.minargs }
149
- assert_raises{ subject.minargs(1) }
147
+ assert_that { subject.minargs }.raises
148
+ assert_that { subject.minargs(1) }.raises
150
149
 
151
- assert_raises{ subject.withblock(1) }
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
- @module = TestModule
159
- Assert.stub(@module, :noargs){ "default" }
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(@module, :withargs){ "default" }
163
- Assert.stub(@module, :withargs).with(1){ "one" }
162
+ Assert.stub(subject, :withargs){ "default" }
163
+ Assert.stub(subject, :withargs).with(1){ "one" }
164
164
 
165
- Assert.stub(@module, :anyargs){ "default" }
166
- Assert.stub(@module, :anyargs).with(1, 2){ "one-two" }
165
+ Assert.stub(subject, :anyargs){ "default" }
166
+ Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
167
167
 
168
- Assert.stub(@module, :minargs){ "default" }
169
- Assert.stub(@module, :minargs).with(1, 2){ "one-two" }
170
- Assert.stub(@module, :minargs).with(1, 2, 3){ "one-two-three" }
168
+ Assert.stub(subject, :minargs){ "default" }
169
+ Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
170
+ Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
171
171
 
172
- Assert.stub(@module, :withblock){ "default" }
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
- assert_equal "none", subject.noargs
176
+ assert_that(subject.noargs).equals("none")
178
177
  end
179
178
 
180
179
  should "allow stubbing a method that takes args" do
181
- assert_equal "one", subject.withargs(1)
182
- assert_equal "default", subject.withargs(2)
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
- assert_equal "default", subject.anyargs
187
- assert_equal "default", subject.anyargs(1)
188
- assert_equal "one-two", subject.anyargs(1, 2)
185
+ assert_that(subject.anyargs).equals("default")
186
+ assert_that(subject.anyargs(1)).equals("default")
187
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
189
188
  end
190
189
 
191
190
  should "allow stubbing a method that takes a minimum number of args" do
192
- assert_equal "one-two", subject.minargs(1, 2)
193
- assert_equal "one-two-three", subject.minargs(1, 2, 3)
194
- assert_equal "default", subject.minargs(1, 2, 4)
195
- assert_equal "default", subject.minargs(1, 2, 3, 4)
191
+ assert_that(subject.minargs(1, 2)).equals("one-two")
192
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
193
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
194
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
196
195
  end
197
196
 
198
197
  should "allow stubbing a method that takes a block" do
199
- assert_equal "default", subject.withblock
200
- assert_equal "default", subject.withblock{ "my-block" }
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
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
203
+ assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
205
204
 
206
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
207
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
205
+ assert_that { Assert.stub(subject, :withargs).with{ } }.raises
206
+ assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
208
207
 
209
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
210
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
208
+ assert_that { Assert.stub(subject, :minargs).with{ } }.raises
209
+ assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
211
210
 
212
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
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
- assert_raises{ subject.noargs(1) }
215
+ assert_that { subject.noargs(1) }.raises
217
216
 
218
- assert_raises{ subject.withargs }
219
- assert_raises{ subject.withargs(1, 2) }
217
+ assert_that { subject.withargs }.raises
218
+ assert_that { subject.withargs(1, 2) }.raises
220
219
 
221
- assert_raises{ subject.minargs }
222
- assert_raises{ subject.minargs(1) }
220
+ assert_that { subject.minargs }.raises
221
+ assert_that { subject.minargs(1) }.raises
223
222
 
224
- assert_raises{ subject.withblock(1) }
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
- @class = Class.new{ extend TestMixin }
232
- Assert.stub(@class, :noargs){ "default" }
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(@class, :withargs){ "default" }
236
- Assert.stub(@class, :withargs).with(1){ "one" }
235
+ Assert.stub(subject, :withargs){ "default" }
236
+ Assert.stub(subject, :withargs).with(1){ "one" }
237
237
 
238
- Assert.stub(@class, :anyargs){ "default" }
239
- Assert.stub(@class, :anyargs).with(1, 2){ "one-two" }
238
+ Assert.stub(subject, :anyargs){ "default" }
239
+ Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
240
240
 
241
- Assert.stub(@class, :minargs){ "default" }
242
- Assert.stub(@class, :minargs).with(1, 2){ "one-two" }
243
- Assert.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
241
+ Assert.stub(subject, :minargs){ "default" }
242
+ Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
243
+ Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
244
244
 
245
- Assert.stub(@class, :withblock){ "default" }
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
- assert_equal "none", subject.noargs
249
+ assert_that(subject.noargs).equals("none")
251
250
  end
252
251
 
253
252
  should "allow stubbing a method that takes args" do
254
- assert_equal "one", subject.withargs(1)
255
- assert_equal "default", subject.withargs(2)
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
- assert_equal "default", subject.anyargs
260
- assert_equal "default", subject.anyargs(1)
261
- assert_equal "one-two", subject.anyargs(1, 2)
258
+ assert_that(subject.anyargs).equals("default")
259
+ assert_that(subject.anyargs(1)).equals("default")
260
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
262
261
  end
263
262
 
264
263
  should "allow stubbing a method that takes a minimum number of args" do
265
- assert_equal "one-two", subject.minargs(1, 2)
266
- assert_equal "one-two-three", subject.minargs(1, 2, 3)
267
- assert_equal "default", subject.minargs(1, 2, 4)
268
- assert_equal "default", subject.minargs(1, 2, 3, 4)
264
+ assert_that(subject.minargs(1, 2)).equals("one-two")
265
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
266
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
267
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
269
268
  end
270
269
 
271
270
  should "allow stubbing a method that takes a block" do
272
- assert_equal "default", subject.withblock
273
- assert_equal "default", subject.withblock{ "my-block" }
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
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
276
+ assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
278
277
 
279
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
280
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
278
+ assert_that { Assert.stub(subject, :withargs).with{ } }.raises
279
+ assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
281
280
 
282
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
283
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
281
+ assert_that { Assert.stub(subject, :minargs).with{ } }.raises
282
+ assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
284
283
 
285
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
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
- assert_raises{ subject.noargs(1) }
288
+ assert_that { subject.noargs(1) }.raises
290
289
 
291
- assert_raises{ subject.withargs }
292
- assert_raises{ subject.withargs(1, 2) }
290
+ assert_that { subject.withargs }.raises
291
+ assert_that { subject.withargs(1, 2) }.raises
293
292
 
294
- assert_raises{ subject.minargs }
295
- assert_raises{ subject.minargs(1) }
293
+ assert_that { subject.minargs }.raises
294
+ assert_that { subject.minargs(1) }.raises
296
295
 
297
- assert_raises{ subject.withblock(1) }
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
- @class = Class.new{ include TestMixin }
305
- @instance = @class.new
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(@instance, :withargs){ "default" }
310
- Assert.stub(@instance, :withargs).with(1){ "one" }
310
+ Assert.stub(subject, :withargs){ "default" }
311
+ Assert.stub(subject, :withargs).with(1){ "one" }
311
312
 
312
- Assert.stub(@instance, :anyargs){ "default" }
313
- Assert.stub(@instance, :anyargs).with(1, 2){ "one-two" }
313
+ Assert.stub(subject, :anyargs){ "default" }
314
+ Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
314
315
 
315
- Assert.stub(@instance, :minargs){ "default" }
316
- Assert.stub(@instance, :minargs).with(1, 2){ "one-two" }
317
- Assert.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
316
+ Assert.stub(subject, :minargs){ "default" }
317
+ Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
318
+ Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
318
319
 
319
- Assert.stub(@instance, :withblock){ "default" }
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
- assert_equal "none", subject.noargs
324
+ assert_that(subject.noargs).equals("none")
325
325
  end
326
326
 
327
327
  should "allow stubbing a method that takes args" do
328
- assert_equal "one", subject.withargs(1)
329
- assert_equal "default", subject.withargs(2)
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
- assert_equal "default", subject.anyargs
334
- assert_equal "default", subject.anyargs(1)
335
- assert_equal "one-two", subject.anyargs(1, 2)
333
+ assert_that(subject.anyargs).equals("default")
334
+ assert_that(subject.anyargs(1)).equals("default")
335
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
336
336
  end
337
337
 
338
338
  should "allow stubbing a method that takes a minimum number of args" do
339
- assert_equal "one-two", subject.minargs(1, 2)
340
- assert_equal "one-two-three", subject.minargs(1, 2, 3)
341
- assert_equal "default", subject.minargs(1, 2, 4)
342
- assert_equal "default", subject.minargs(1, 2, 3, 4)
339
+ assert_that(subject.minargs(1, 2)).equals("one-two")
340
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
341
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
342
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
343
343
  end
344
344
 
345
345
  should "allow stubbing a method that takes a block" do
346
- assert_equal "default", subject.withblock
347
- assert_equal "default", subject.withblock{ "my-block" }
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
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
351
+ assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
352
352
 
353
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
354
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
353
+ assert_that { Assert.stub(subject, :withargs).with{ } }.raises
354
+ assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
355
355
 
356
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
357
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
356
+ assert_that { Assert.stub(subject, :minargs).with{ } }.raises
357
+ assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
358
358
 
359
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
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
- assert_raises{ subject.noargs(1) }
363
+ assert_that { subject.noargs(1) }.raises
364
364
 
365
- assert_raises{ subject.withargs }
366
- assert_raises{ subject.withargs(1, 2) }
365
+ assert_that { subject.withargs }.raises
366
+ assert_that { subject.withargs(1, 2) }.raises
367
367
 
368
- assert_raises{ subject.minargs }
369
- assert_raises{ subject.minargs(1) }
368
+ assert_that { subject.minargs }.raises
369
+ assert_that { subject.minargs(1) }.raises
370
370
 
371
- assert_raises{ subject.withblock(1) }
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
- @class = Class.new(TestClass)
379
- Assert.stub(@class, :noargs){ "default" }
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(@class, :withargs){ "default" }
383
- Assert.stub(@class, :withargs).with(1){ "one" }
383
+ Assert.stub(subject, :withargs){ "default" }
384
+ Assert.stub(subject, :withargs).with(1){ "one" }
384
385
 
385
- Assert.stub(@class, :anyargs){ "default" }
386
- Assert.stub(@class, :anyargs).with(1, 2){ "one-two" }
386
+ Assert.stub(subject, :anyargs){ "default" }
387
+ Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
387
388
 
388
- Assert.stub(@class, :minargs){ "default" }
389
- Assert.stub(@class, :minargs).with(1, 2){ "one-two" }
390
- Assert.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
389
+ Assert.stub(subject, :minargs){ "default" }
390
+ Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
391
+ Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
391
392
 
392
- Assert.stub(@class, :withblock){ "default" }
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
- assert_equal "none", subject.noargs
397
+ assert_that(subject.noargs).equals("none")
398
398
  end
399
399
 
400
400
  should "allow stubbing a method that takes args" do
401
- assert_equal "one", subject.withargs(1)
402
- assert_equal "default", subject.withargs(2)
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
- assert_equal "default", subject.anyargs
407
- assert_equal "default", subject.anyargs(1)
408
- assert_equal "one-two", subject.anyargs(1, 2)
406
+ assert_that(subject.anyargs).equals("default")
407
+ assert_that(subject.anyargs(1)).equals("default")
408
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
409
409
  end
410
410
 
411
411
  should "allow stubbing a method that takes a minimum number of args" do
412
- assert_equal "one-two", subject.minargs(1, 2)
413
- assert_equal "one-two-three", subject.minargs(1, 2, 3)
414
- assert_equal "default", subject.minargs(1, 2, 4)
415
- assert_equal "default", subject.minargs(1, 2, 3, 4)
412
+ assert_that(subject.minargs(1, 2)).equals("one-two")
413
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
414
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
415
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
416
416
  end
417
417
 
418
418
  should "allow stubbing a method that takes a block" do
419
- assert_equal "default", subject.withblock
420
- assert_equal "default", subject.withblock{ "my-block" }
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
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
424
+ assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
425
425
 
426
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
427
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
426
+ assert_that { Assert.stub(subject, :withargs).with{ } }.raises
427
+ assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
428
428
 
429
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
430
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
429
+ assert_that { Assert.stub(subject, :minargs).with{ } }.raises
430
+ assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
431
431
 
432
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
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
- assert_raises{ subject.noargs(1) }
436
+ assert_that { subject.noargs(1) }.raises
437
437
 
438
- assert_raises{ subject.withargs }
439
- assert_raises{ subject.withargs(1, 2) }
438
+ assert_that { subject.withargs }.raises
439
+ assert_that { subject.withargs(1, 2) }.raises
440
440
 
441
- assert_raises{ subject.minargs }
442
- assert_raises{ subject.minargs(1) }
441
+ assert_that { subject.minargs }.raises
442
+ assert_that { subject.minargs(1) }.raises
443
443
 
444
- assert_raises{ subject.withblock(1) }
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
- @class = Class.new(TestClass)
452
- @instance = @class.new
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(@instance, :withargs){ "default" }
457
- Assert.stub(@instance, :withargs).with(1){ "one" }
456
+ Assert.stub(subject, :withargs){ "default" }
457
+ Assert.stub(subject, :withargs).with(1){ "one" }
458
458
 
459
- Assert.stub(@instance, :anyargs){ "default" }
460
- Assert.stub(@instance, :anyargs).with(1, 2){ "one-two" }
459
+ Assert.stub(subject, :anyargs){ "default" }
460
+ Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
461
461
 
462
- Assert.stub(@instance, :minargs){ "default" }
463
- Assert.stub(@instance, :minargs).with(1, 2){ "one-two" }
464
- Assert.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
462
+ Assert.stub(subject, :minargs){ "default" }
463
+ Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
464
+ Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
465
465
 
466
- Assert.stub(@instance, :withblock){ "default" }
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
- assert_equal "none", subject.noargs
470
+ assert_that(subject.noargs).equals("none")
472
471
  end
473
472
 
474
473
  should "allow stubbing a method that takes args" do
475
- assert_equal "one", subject.withargs(1)
476
- assert_equal "default", subject.withargs(2)
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
- assert_equal "default", subject.anyargs
481
- assert_equal "default", subject.anyargs(1)
482
- assert_equal "one-two", subject.anyargs(1, 2)
479
+ assert_that(subject.anyargs).equals("default")
480
+ assert_that(subject.anyargs(1)).equals("default")
481
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
483
482
  end
484
483
 
485
484
  should "allow stubbing a method that takes a minimum number of args" do
486
- assert_equal "one-two", subject.minargs(1, 2)
487
- assert_equal "one-two-three", subject.minargs(1, 2, 3)
488
- assert_equal "default", subject.minargs(1, 2, 4)
489
- assert_equal "default", subject.minargs(1, 2, 3, 4)
485
+ assert_that(subject.minargs(1, 2)).equals("one-two")
486
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
487
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
488
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
490
489
  end
491
490
 
492
491
  should "allow stubbing a method that takes a block" do
493
- assert_equal "default", subject.withblock
494
- assert_equal "default", subject.withblock{ "my-block" }
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
- assert_raises{ Assert.stub(subject, :noargs).with(1){ } }
497
+ assert_that { Assert.stub(subject, :noargs).with(1){ } }.raises
499
498
 
500
- assert_raises{ Assert.stub(subject, :withargs).with{ } }
501
- assert_raises{ Assert.stub(subject, :withargs).with(1, 2){ } }
499
+ assert_that { Assert.stub(subject, :withargs).with{ } }.raises
500
+ assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.raises
502
501
 
503
- assert_raises{ Assert.stub(subject, :minargs).with{ } }
504
- assert_raises{ Assert.stub(subject, :minargs).with(1){ } }
502
+ assert_that { Assert.stub(subject, :minargs).with{ } }.raises
503
+ assert_that { Assert.stub(subject, :minargs).with(1){ } }.raises
505
504
 
506
- assert_raises{ Assert.stub(subject, :withblock).with(1){ } }
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
- assert_raises{ subject.noargs(1) }
509
+ assert_that { subject.noargs(1) }.raises
511
510
 
512
- assert_raises{ subject.withargs }
513
- assert_raises{ subject.withargs(1, 2) }
511
+ assert_that { subject.withargs }.raises
512
+ assert_that { subject.withargs(1, 2) }.raises
514
513
 
515
- assert_raises{ subject.minargs }
516
- assert_raises{ subject.minargs(1) }
514
+ assert_that { subject.minargs }.raises
515
+ assert_that { subject.minargs(1) }.raises
517
516
 
518
- assert_raises{ subject.withblock(1) }
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
- @class = DelegateClass
526
- Assert.stub(@class, :noargs){ "default" }
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(@class, :withargs){ "default" }
530
- Assert.stub(@class, :withargs).with(1){ "one" }
529
+ Assert.stub(subject, :withargs){ "default" }
530
+ Assert.stub(subject, :withargs).with(1){ "one" }
531
531
 
532
- Assert.stub(@class, :anyargs){ "default" }
533
- Assert.stub(@class, :anyargs).with(1, 2){ "one-two" }
532
+ Assert.stub(subject, :anyargs){ "default" }
533
+ Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
534
534
 
535
- Assert.stub(@class, :minargs){ "default" }
536
- Assert.stub(@class, :minargs).with(1, 2){ "one-two" }
537
- Assert.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
535
+ Assert.stub(subject, :minargs){ "default" }
536
+ Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
537
+ Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
538
538
 
539
- Assert.stub(@class, :withblock){ "default" }
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
- assert_equal "none", subject.noargs
543
+ assert_that(subject.noargs).equals("none")
545
544
  end
546
545
 
547
546
  should "allow stubbing a method that takes args" do
548
- assert_equal "one", subject.withargs(1)
549
- assert_equal "default", subject.withargs(2)
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
- assert_equal "default", subject.anyargs
554
- assert_equal "default", subject.anyargs(1)
555
- assert_equal "one-two", subject.anyargs(1, 2)
552
+ assert_that(subject.anyargs).equals("default")
553
+ assert_that(subject.anyargs(1)).equals("default")
554
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
556
555
  end
557
556
 
558
557
  should "allow stubbing a method that takes a minimum number of args" do
559
- assert_equal "one-two", subject.minargs(1, 2)
560
- assert_equal "one-two-three", subject.minargs(1, 2, 3)
561
- assert_equal "default", subject.minargs(1, 2, 4)
562
- assert_equal "default", subject.minargs(1, 2, 3, 4)
558
+ assert_that(subject.minargs(1, 2)).equals("one-two")
559
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
560
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
561
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
563
562
  end
564
563
 
565
564
  should "allow stubbing a method that takes a block" do
566
- assert_equal "default", subject.withblock
567
- assert_equal "default", subject.withblock{ "my-block" }
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
- assert_nothing_raised{ Assert.stub(subject, :noargs).with(1){ } }
570
+ assert_that { Assert.stub(subject, :noargs).with(1){ } }.does_not_raise
572
571
 
573
- assert_nothing_raised{ Assert.stub(subject, :withargs).with{ } }
574
- assert_nothing_raised{ Assert.stub(subject, :withargs).with(1, 2){ } }
572
+ assert_that { Assert.stub(subject, :withargs).with{ } }.does_not_raise
573
+ assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.does_not_raise
575
574
 
576
- assert_nothing_raised{ Assert.stub(subject, :minargs).with{ } }
577
- assert_nothing_raised{ Assert.stub(subject, :minargs).with(1){ } }
575
+ assert_that { Assert.stub(subject, :minargs).with{ } }.does_not_raise
576
+ assert_that { Assert.stub(subject, :minargs).with(1){ } }.does_not_raise
578
577
 
579
- assert_nothing_raised{ Assert.stub(subject, :withblock).with(1){ } }
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
- assert_nothing_raised{ subject.noargs(1) }
582
+ assert_that { subject.noargs(1) }.does_not_raise
584
583
 
585
- assert_nothing_raised{ subject.withargs }
586
- assert_nothing_raised{ subject.withargs(1, 2) }
584
+ assert_that { subject.withargs }.does_not_raise
585
+ assert_that { subject.withargs(1, 2) }.does_not_raise
587
586
 
588
- assert_nothing_raised{ subject.minargs }
589
- assert_nothing_raised{ subject.minargs(1) }
587
+ assert_that { subject.minargs }.does_not_raise
588
+ assert_that { subject.minargs(1) }.does_not_raise
590
589
 
591
- assert_nothing_raised{ subject.withblock(1) }
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
- @instance = DelegateClass.new
599
- Assert.stub(@instance, :noargs){ "default" }
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(@instance, :withargs){ "default" }
603
- Assert.stub(@instance, :withargs).with(1){ "one" }
602
+ Assert.stub(subject, :withargs){ "default" }
603
+ Assert.stub(subject, :withargs).with(1){ "one" }
604
604
 
605
- Assert.stub(@instance, :anyargs){ "default" }
606
- Assert.stub(@instance, :anyargs).with(1, 2){ "one-two" }
605
+ Assert.stub(subject, :anyargs){ "default" }
606
+ Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
607
607
 
608
- Assert.stub(@instance, :minargs){ "default" }
609
- Assert.stub(@instance, :minargs).with(1, 2){ "one-two" }
610
- Assert.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
608
+ Assert.stub(subject, :minargs){ "default" }
609
+ Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
610
+ Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
611
611
 
612
- Assert.stub(@instance, :withblock){ "default" }
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
- assert_equal "none", subject.noargs
616
+ assert_that(subject.noargs).equals("none")
618
617
  end
619
618
 
620
619
  should "allow stubbing a method that takes args" do
621
- assert_equal "one", subject.withargs(1)
622
- assert_equal "default", subject.withargs(2)
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
- assert_equal "default", subject.anyargs
627
- assert_equal "default", subject.anyargs(1)
628
- assert_equal "one-two", subject.anyargs(1, 2)
625
+ assert_that(subject.anyargs).equals("default")
626
+ assert_that(subject.anyargs(1)).equals("default")
627
+ assert_that(subject.anyargs(1, 2)).equals("one-two")
629
628
  end
630
629
 
631
630
  should "allow stubbing a method that takes a minimum number of args" do
632
- assert_equal "one-two", subject.minargs(1, 2)
633
- assert_equal "one-two-three", subject.minargs(1, 2, 3)
634
- assert_equal "default", subject.minargs(1, 2, 4)
635
- assert_equal "default", subject.minargs(1, 2, 3, 4)
631
+ assert_that(subject.minargs(1, 2)).equals("one-two")
632
+ assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
633
+ assert_that(subject.minargs(1, 2, 4)).equals("default")
634
+ assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
636
635
  end
637
636
 
638
637
  should "allow stubbing a method that takes a block" do
639
- assert_equal "default", subject.withblock
640
- assert_equal "default", subject.withblock{ "my-block" }
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
- assert_nothing_raised{ Assert.stub(subject, :noargs).with(1){ } }
643
+ assert_that { Assert.stub(subject, :noargs).with(1){ } }.does_not_raise
645
644
 
646
- assert_nothing_raised{ Assert.stub(subject, :withargs).with{ } }
647
- assert_nothing_raised{ Assert.stub(subject, :withargs).with(1, 2){ } }
645
+ assert_that { Assert.stub(subject, :withargs).with{ } }.does_not_raise
646
+ assert_that { Assert.stub(subject, :withargs).with(1, 2){ } }.does_not_raise
648
647
 
649
- assert_nothing_raised{ Assert.stub(subject, :minargs).with{ } }
650
- assert_nothing_raised{ Assert.stub(subject, :minargs).with(1){ } }
648
+ assert_that { Assert.stub(subject, :minargs).with{ } }.does_not_raise
649
+ assert_that { Assert.stub(subject, :minargs).with(1){ } }.does_not_raise
651
650
 
652
- assert_nothing_raised{ Assert.stub(subject, :withblock).with(1){ } }
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
- assert_nothing_raised{ subject.noargs(1) }
655
+ assert_that { subject.noargs(1) }.does_not_raise
657
656
 
658
- assert_nothing_raised{ subject.withargs }
659
- assert_nothing_raised{ subject.withargs(1, 2) }
657
+ assert_that { subject.withargs }.does_not_raise
658
+ assert_that { subject.withargs(1, 2) }.does_not_raise
660
659
 
661
- assert_nothing_raised{ subject.minargs }
662
- assert_nothing_raised{ subject.minargs(1) }
660
+ assert_that { subject.minargs }.does_not_raise
661
+ assert_that { subject.minargs(1) }.does_not_raise
663
662
 
664
- assert_nothing_raised{ subject.withblock(1) }
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
- @parent_class = Class.new
672
- @child_class = Class.new(@parent_class)
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
- assert_equal "parent", @parent_class.new
680
- assert_equal "child", @child_class.new
678
+ assert_that(parent_class.new).equals("parent")
679
+ assert_that(child_class.new).equals("child")
681
680
  end
682
681
  end
683
682