rspec 1.2.2 → 1.2.3
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.
- data/History.rdoc +31 -1
- data/Manifest.txt +14 -12
- data/Rakefile +1 -1
- data/Upgrade.rdoc +43 -3
- data/examples/failing/failing_implicit_docstrings_example.rb +5 -5
- data/examples/passing/implicit_docstrings_example.rb +3 -3
- data/features/before_and_after_blocks/before_and_after_blocks.feature +20 -21
- data/features/example_groups/example_group_with_should_methods.feature +20 -8
- data/features/example_groups/implicit_docstrings.feature +36 -20
- data/features/example_groups/nested_groups.feature +25 -10
- data/features/extensions/custom_example_group.feature +19 -0
- data/features/formatters/custom_formatter.feature +30 -0
- data/features/heckle/heckle.feature +7 -7
- data/features/interop/examples_and_tests_together.feature +63 -14
- data/features/interop/rspec_output.feature +25 -0
- data/features/interop/test_but_not_test_unit.feature +19 -7
- data/features/interop/test_case_with_should_methods.feature +37 -8
- data/features/matchers/{create_matcher.feature → define_matcher.feature} +54 -30
- data/features/matchers/{create_matcher_outside_rspec.feature → define_matcher_outside_rspec.feature} +7 -7
- data/features/mock_framework_integration/use_flexmock.feature +3 -3
- data/features/mock_framework_integration/use_mocha.feature +3 -3
- data/features/mock_framework_integration/use_rr.feature +3 -3
- data/features/mocks/mix_stubs_and_mocks.feature +4 -4
- data/features/pending/pending_examples.feature +18 -18
- data/features/runner/specify_line_number.feature +32 -0
- data/features/step_definitions/running_rspec_steps.rb +41 -0
- data/features/subject/explicit_subject.feature +4 -4
- data/features/subject/implicit_subject.feature +4 -4
- data/features/support/env.rb +64 -11
- data/features/support/matchers/smart_match.rb +10 -35
- data/lib/spec.rb +1 -0
- data/lib/spec/deprecation.rb +40 -0
- data/lib/spec/dsl/main.rb +10 -5
- data/lib/spec/example.rb +1 -27
- data/lib/spec/example/args_and_options.rb +27 -0
- data/lib/spec/example/before_and_after_hooks.rb +30 -21
- data/lib/spec/example/errors.rb +8 -18
- data/lib/spec/example/example_group_factory.rb +0 -4
- data/lib/spec/example/example_group_methods.rb +27 -41
- data/lib/spec/example/example_group_proxy.rb +12 -22
- data/lib/spec/example/example_methods.rb +8 -18
- data/lib/spec/example/example_proxy.rb +4 -4
- data/lib/spec/example/pending.rb +3 -4
- data/lib/spec/example/predicate_matchers.rb +1 -1
- data/lib/spec/example/subject.rb +2 -0
- data/lib/spec/expectations.rb +1 -26
- data/lib/spec/expectations/extensions.rb +1 -1
- data/lib/spec/expectations/extensions/kernel.rb +52 -0
- data/lib/spec/expectations/handler.rb +21 -10
- data/lib/spec/matchers/be.rb +3 -3
- data/lib/spec/matchers/be_close.rb +17 -21
- data/lib/spec/matchers/be_instance_of.rb +7 -26
- data/lib/spec/matchers/be_kind_of.rb +7 -26
- data/lib/spec/matchers/dsl.rb +9 -4
- data/lib/spec/matchers/eql.rb +24 -25
- data/lib/spec/matchers/equal.rb +25 -25
- data/lib/spec/matchers/exist.rb +5 -21
- data/lib/spec/matchers/include.rb +22 -44
- data/lib/spec/matchers/match.rb +5 -25
- data/lib/spec/matchers/match_array.rb +8 -4
- data/lib/spec/matchers/matcher.rb +13 -2
- data/lib/spec/matchers/pretty.rb +1 -0
- data/lib/spec/matchers/simple_matcher.rb +2 -2
- data/lib/spec/mocks/mock.rb +10 -10
- data/lib/spec/mocks/spec_methods.rb +1 -1
- data/lib/spec/runner/configuration.rb +53 -42
- data/lib/spec/{expectations → runner}/differs/default.rb +0 -0
- data/lib/spec/{expectations → runner}/differs/load-diff-lcs.rb +0 -0
- data/lib/spec/runner/drb_command_line.rb +1 -1
- data/lib/spec/runner/example_group_runner.rb +0 -12
- data/lib/spec/runner/formatter/base_formatter.rb +77 -30
- data/lib/spec/runner/formatter/base_text_formatter.rb +19 -24
- data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +1 -1
- data/lib/spec/runner/formatter/html_formatter.rb +4 -6
- data/lib/spec/runner/formatter/nested_text_formatter.rb +2 -2
- data/lib/spec/runner/formatter/no_op_method_missing.rb +21 -0
- data/lib/spec/runner/formatter/profile_formatter.rb +0 -4
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +4 -5
- data/lib/spec/runner/formatter/silent_formatter.rb +10 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +2 -2
- data/lib/spec/runner/option_parser.rb +14 -7
- data/lib/spec/runner/options.rb +17 -7
- data/lib/spec/runner/reporter.rb +69 -64
- data/lib/spec/version.rb +1 -1
- data/spec/spec/dsl/main_spec.rb +7 -0
- data/spec/spec/example/example_group_methods_spec.rb +16 -32
- data/spec/spec/example/example_group_proxy_spec.rb +25 -5
- data/spec/spec/example/example_group_spec.rb +2 -2
- data/spec/spec/example/example_methods_spec.rb +19 -24
- data/spec/spec/example/example_proxy_spec.rb +11 -1
- data/spec/spec/example/pending_module_spec.rb +2 -108
- data/spec/spec/example/predicate_matcher_spec.rb +23 -3
- data/spec/spec/expectations/extensions/object_spec.rb +9 -9
- data/spec/spec/expectations/fail_with_spec.rb +13 -13
- data/spec/spec/expectations/handler_spec.rb +44 -15
- data/spec/spec/matchers/be_close_spec.rb +9 -0
- data/spec/spec/matchers/be_instance_of_spec.rb +6 -4
- data/spec/spec/matchers/be_kind_of_spec.rb +5 -3
- data/spec/spec/matchers/be_spec.rb +1 -5
- data/spec/spec/matchers/compatibility_spec.rb +1 -1
- data/spec/spec/matchers/dsl_spec.rb +10 -1
- data/spec/spec/matchers/eql_spec.rb +8 -4
- data/spec/spec/matchers/equal_spec.rb +8 -4
- data/spec/spec/matchers/exist_spec.rb +1 -1
- data/spec/spec/matchers/include_spec.rb +1 -1
- data/spec/spec/matchers/match_array_spec.rb +26 -1
- data/spec/spec/matchers/match_spec.rb +2 -2
- data/spec/spec/matchers/matcher_methods_spec.rb +0 -3
- data/spec/spec/matchers/matcher_spec.rb +53 -0
- data/spec/spec/matchers/operator_matcher_spec.rb +1 -1
- data/spec/spec/mocks/mock_spec.rb +6 -0
- data/spec/spec/runner/configuration_spec.rb +11 -1
- data/spec/spec/runner/drb_command_line_spec.rb +13 -1
- data/spec/spec/runner/example_group_runner_spec.rb +0 -7
- data/spec/spec/runner/formatter/base_formatter_spec.rb +19 -12
- data/spec/spec/runner/formatter/base_text_formatter_spec.rb +2 -2
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +4 -4
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +2 -2
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +31 -34
- data/spec/spec/runner/formatter/html_formatter_spec.rb +20 -0
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -20
- data/spec/spec/runner/formatter/profile_formatter_spec.rb +22 -3
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +24 -3
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +25 -28
- data/spec/spec/runner/formatter/text_mate_formatter_spec.rb +2 -2
- data/spec/spec/runner/option_parser_spec.rb +108 -40
- data/spec/spec/runner/reporter_spec.rb +16 -17
- data/spec/spec_helper.rb +4 -1
- metadata +20 -18
- data/features/example_groups/output.feature +0 -20
- data/features/step_definitions/running_rspec.rb +0 -69
- data/lib/spec/expectations/extensions/object.rb +0 -63
- data/resources/spec/example_group_with_should_methods.rb +0 -12
- data/resources/spec/simple_spec.rb +0 -8
- data/resources/test/spec_and_test_together.rb +0 -56
- data/resources/test/spec_including_test_but_not_unit.rb +0 -11
- data/resources/test/test_case_with_should_methods.rb +0 -29
@@ -1,7 +1,7 @@
|
|
1
1
|
module Spec
|
2
2
|
module Example
|
3
|
-
# Lightweight
|
4
|
-
#
|
3
|
+
# Lightweight proxy for an example group. This is the object that is passed
|
4
|
+
# to Spec::Runner::Formatter::BaseFormatter#example_group_started
|
5
5
|
class ExampleGroupProxy
|
6
6
|
|
7
7
|
def initialize(example_group) # :nodoc:
|
@@ -9,37 +9,38 @@ module Spec
|
|
9
9
|
@nested_descriptions = example_group.nested_descriptions
|
10
10
|
@examples = example_group.example_proxies
|
11
11
|
@location = example_group.location
|
12
|
-
@backtrace = example_group.backtrace
|
12
|
+
@backtrace = example_group.location # deprecated - see the backtrace method below
|
13
13
|
end
|
14
14
|
|
15
|
-
# This is the
|
15
|
+
# This is the description passed to the <tt>describe()</tt> method or any
|
16
16
|
# of its aliases
|
17
17
|
attr_reader :description
|
18
18
|
|
19
19
|
# Used by Spec::Runner::Formatter::NestedTextFormatter to access the
|
20
|
-
#
|
20
|
+
# description of each example group in a nested group separately.
|
21
21
|
attr_reader :nested_descriptions
|
22
22
|
|
23
|
-
# A collection of ExampleGroupProxy
|
23
|
+
# A collection of ExampleGroupProxy objects, one for each example
|
24
24
|
# declared in this group.
|
25
25
|
attr_reader :examples
|
26
26
|
|
27
|
-
# The file and line number at which the
|
27
|
+
# The file and line number at which the proxied example group
|
28
28
|
# was declared. This is extracted from <tt>caller</tt>, and is therefore
|
29
29
|
# formatted as an individual line in a backtrace.
|
30
30
|
attr_reader :location
|
31
31
|
|
32
32
|
# Deprecated - use location() instead
|
33
33
|
def backtrace
|
34
|
+
Spec::deprecate("ExampleGroupProxy#backtrace","ExampleGroupProxy#location")
|
34
35
|
@backtrace
|
35
36
|
end
|
36
37
|
|
37
|
-
#
|
38
|
-
# matching the submitted regexp removed.
|
38
|
+
# Deprecated - just use gsub on the description instead.
|
39
39
|
def filtered_description(regexp)
|
40
|
-
|
40
|
+
Spec::deprecate("ExampleGroupProxy#filtered_description","gsub (or similar) to modify ExampleGroupProxy#description")
|
41
|
+
ExampleGroupMethods.build_description_from(
|
41
42
|
*nested_descriptions.collect do |description|
|
42
|
-
description =~ regexp ? $1 : description
|
43
|
+
description =~ regexp ? description.gsub($1, "") : description
|
43
44
|
end
|
44
45
|
)
|
45
46
|
end
|
@@ -47,17 +48,6 @@ module Spec
|
|
47
48
|
def ==(other) # :nodoc:
|
48
49
|
other.description == description
|
49
50
|
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
# FIXME - this is duplicated from ExampleGroupMethods
|
54
|
-
def build_description_from(*args)
|
55
|
-
text = args.inject("") do |description, arg|
|
56
|
-
description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/)
|
57
|
-
description << arg.to_s
|
58
|
-
end
|
59
|
-
text == "" ? nil : text
|
60
|
-
end
|
61
51
|
end
|
62
52
|
end
|
63
53
|
end
|
@@ -18,7 +18,11 @@ module Spec
|
|
18
18
|
# description
|
19
19
|
# => "should start with a balance of 0"
|
20
20
|
def description
|
21
|
-
@_proxy.description || ::Spec::Matchers.generated_description
|
21
|
+
if description = @_proxy.description || ::Spec::Matchers.generated_description
|
22
|
+
description
|
23
|
+
else
|
24
|
+
raise Spec::Example::NoDescriptionError.new("example", @_proxy.location)
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
def options # :nodoc:
|
@@ -81,20 +85,6 @@ module Spec
|
|
81
85
|
end
|
82
86
|
end
|
83
87
|
|
84
|
-
# Provides the backtrace up to where this example was declared.
|
85
|
-
def backtrace
|
86
|
-
@_backtrace
|
87
|
-
end
|
88
|
-
|
89
|
-
# Deprecated - use +backtrace()+
|
90
|
-
def implementation_backtrace
|
91
|
-
Kernel.warn <<-WARNING
|
92
|
-
ExampleMethods#implementation_backtrace is deprecated and will be removed
|
93
|
-
from a future version. Please use ExampleMethods#backtrace instead.
|
94
|
-
WARNING
|
95
|
-
backtrace
|
96
|
-
end
|
97
|
-
|
98
88
|
# Run all the before(:each) blocks for this example
|
99
89
|
def run_before_each
|
100
90
|
example_group_hierarchy.run_before_each(self)
|
@@ -116,19 +106,19 @@ WARNING
|
|
116
106
|
include Matchers
|
117
107
|
include Pending
|
118
108
|
|
119
|
-
def before_each_example
|
109
|
+
def before_each_example
|
120
110
|
setup_mocks_for_rspec
|
121
111
|
run_before_each
|
122
112
|
end
|
123
113
|
|
124
|
-
def after_each_example
|
114
|
+
def after_each_example
|
125
115
|
run_after_each
|
126
116
|
verify_mocks_for_rspec
|
127
117
|
ensure
|
128
118
|
teardown_mocks_for_rspec
|
129
119
|
end
|
130
120
|
|
131
|
-
def described_class
|
121
|
+
def described_class
|
132
122
|
self.class.described_class
|
133
123
|
end
|
134
124
|
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Spec
|
2
2
|
module Example
|
3
|
-
# Lightweight
|
4
|
-
#
|
5
|
-
# Spec::Runner::Formatter::BaseFormatter
|
3
|
+
# Lightweight proxy for an example. This is the object that is passed to
|
4
|
+
# example-related methods in Spec::Runner::Formatter::BaseFormatter
|
6
5
|
class ExampleProxy
|
7
6
|
|
8
7
|
def initialize(description=nil, options={}, location=nil) # :nodoc:
|
@@ -24,6 +23,7 @@ module Spec
|
|
24
23
|
|
25
24
|
# Deprecated - use location()
|
26
25
|
def backtrace
|
26
|
+
Spec.deprecate("ExampleProxy#backtrace","ExampleProxy#location")
|
27
27
|
location
|
28
28
|
end
|
29
29
|
|
@@ -35,7 +35,7 @@ module Spec
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def ==(other) # :nodoc:
|
38
|
-
(other.description == description) & (other.
|
38
|
+
(other.description == description) & (other.location == location)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/lib/spec/example/pending.rb
CHANGED
@@ -2,16 +2,15 @@ module Spec
|
|
2
2
|
module Example
|
3
3
|
module Pending
|
4
4
|
def pending(message = "TODO")
|
5
|
-
pending_caller = caller[0]
|
6
5
|
if block_given?
|
7
6
|
begin
|
8
7
|
yield
|
9
|
-
rescue Exception
|
10
|
-
raise Spec::Example::ExamplePendingError.new(message
|
8
|
+
rescue Exception
|
9
|
+
raise Spec::Example::ExamplePendingError.new(message)
|
11
10
|
end
|
12
11
|
raise Spec::Example::PendingExampleFixedError.new("Expected pending '#{message}' to fail. No Error was raised.")
|
13
12
|
else
|
14
|
-
raise Spec::Example::ExamplePendingError.new(message
|
13
|
+
raise Spec::Example::ExamplePendingError.new(message)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
data/lib/spec/example/subject.rb
CHANGED
data/lib/spec/expectations.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec/matchers'
|
2
|
+
require 'spec/expectations/fail_with'
|
2
3
|
require 'spec/expectations/errors'
|
3
4
|
require 'spec/expectations/extensions'
|
4
5
|
require 'spec/expectations/handler'
|
@@ -30,31 +31,5 @@ module Spec
|
|
30
31
|
# RSpec ships with a standard set of useful matchers, and writing your own
|
31
32
|
# matchers is quite simple. See Spec::Matchers for details.
|
32
33
|
module Expectations
|
33
|
-
def self.differ
|
34
|
-
defined?(@differ) ? @differ : nil
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.differ=(differ)
|
38
|
-
@differ = differ
|
39
|
-
end
|
40
|
-
|
41
|
-
# raises a Spec::Expectations::ExpectationNotMetError with message
|
42
|
-
#
|
43
|
-
# When a differ has been assigned and fail_with is passed
|
44
|
-
# <code>expected</code> and <code>target</code>, passes them
|
45
|
-
# to the differ to append a diff message to the failure message.
|
46
|
-
def self.fail_with(message, expected=nil, target=nil) # :nodoc:
|
47
|
-
if (Array === message) & (message.length == 3)
|
48
|
-
message, expected, target = message[0], message[1], message[2]
|
49
|
-
end
|
50
|
-
unless (differ.nil? || expected.nil? || target.nil?)
|
51
|
-
if expected.is_a?(String)
|
52
|
-
message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
|
53
|
-
elsif !target.is_a?(Proc)
|
54
|
-
message << "\nDiff:" << self.differ.diff_as_object(target, expected)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
|
58
|
-
end
|
59
34
|
end
|
60
35
|
end
|
@@ -1 +1 @@
|
|
1
|
-
require 'spec/expectations/extensions/
|
1
|
+
require 'spec/expectations/extensions/kernel'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Kernel
|
2
|
+
# :call-seq:
|
3
|
+
# should(matcher)
|
4
|
+
# should == expected
|
5
|
+
# should === expected
|
6
|
+
# should =~ expected
|
7
|
+
#
|
8
|
+
# receiver.should(matcher)
|
9
|
+
# => Passes if matcher.matches?(receiver)
|
10
|
+
#
|
11
|
+
# receiver.should == expected #any value
|
12
|
+
# => Passes if (receiver == expected)
|
13
|
+
#
|
14
|
+
# receiver.should === expected #any value
|
15
|
+
# => Passes if (receiver === expected)
|
16
|
+
#
|
17
|
+
# receiver.should =~ regexp
|
18
|
+
# => Passes if (receiver =~ regexp)
|
19
|
+
#
|
20
|
+
# See Spec::Matchers for more information about matchers
|
21
|
+
#
|
22
|
+
# == Warning
|
23
|
+
#
|
24
|
+
# NOTE that this does NOT support receiver.should != expected.
|
25
|
+
# Instead, use receiver.should_not == expected
|
26
|
+
def should(matcher=nil, &block)
|
27
|
+
Spec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, &block)
|
28
|
+
end
|
29
|
+
|
30
|
+
# :call-seq:
|
31
|
+
# should_not(matcher)
|
32
|
+
# should_not == expected
|
33
|
+
# should_not === expected
|
34
|
+
# should_not =~ expected
|
35
|
+
#
|
36
|
+
# receiver.should_not(matcher)
|
37
|
+
# => Passes unless matcher.matches?(receiver)
|
38
|
+
#
|
39
|
+
# receiver.should_not == expected
|
40
|
+
# => Passes unless (receiver == expected)
|
41
|
+
#
|
42
|
+
# receiver.should_not === expected
|
43
|
+
# => Passes unless (receiver === expected)
|
44
|
+
#
|
45
|
+
# receiver.should_not =~ regexp
|
46
|
+
# => Passes unless (receiver =~ regexp)
|
47
|
+
#
|
48
|
+
# See Spec::Matchers for more information about matchers
|
49
|
+
def should_not(matcher=nil, &block)
|
50
|
+
Spec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, &block)
|
51
|
+
end
|
52
|
+
end
|
@@ -2,7 +2,7 @@ module Spec
|
|
2
2
|
module Expectations
|
3
3
|
class InvalidMatcherError < ArgumentError; end
|
4
4
|
|
5
|
-
class
|
5
|
+
class PositiveExpectationHandler
|
6
6
|
def self.handle_matcher(actual, matcher, &block)
|
7
7
|
::Spec::Matchers.last_should = :should
|
8
8
|
::Spec::Matchers.last_matcher = matcher
|
@@ -10,28 +10,39 @@ module Spec
|
|
10
10
|
|
11
11
|
match = matcher.matches?(actual, &block)
|
12
12
|
return match if match
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
|
14
|
+
message = matcher.respond_to?(:failure_message_for_should) ?
|
15
|
+
matcher.failure_message_for_should :
|
16
|
+
matcher.failure_message
|
17
|
+
|
18
|
+
if matcher.respond_to?(:diffable?) && matcher.diffable?
|
19
|
+
::Spec::Expectations.fail_with message, matcher.expected.first, matcher.actual
|
20
|
+
else
|
21
|
+
::Spec::Expectations.fail_with message
|
22
|
+
end
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
20
|
-
class
|
26
|
+
class NegativeExpectationHandler
|
21
27
|
def self.handle_matcher(actual, matcher, &block)
|
22
28
|
::Spec::Matchers.last_should = :should_not
|
23
29
|
::Spec::Matchers.last_matcher = matcher
|
24
|
-
|
25
30
|
return ::Spec::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
|
26
31
|
|
27
32
|
match = matcher.respond_to?(:does_not_match?) ?
|
28
33
|
!matcher.does_not_match?(actual, &block) :
|
29
34
|
matcher.matches?(actual, &block)
|
30
35
|
return match unless match
|
36
|
+
|
37
|
+
message = matcher.respond_to?(:failure_message_for_should_not) ?
|
38
|
+
matcher.failure_message_for_should_not :
|
39
|
+
matcher.negative_failure_message
|
31
40
|
|
32
|
-
|
33
|
-
|
34
|
-
|
41
|
+
if matcher.respond_to?(:diffable?) && matcher.diffable?
|
42
|
+
::Spec::Expectations.fail_with message, matcher.expected.first, matcher.actual
|
43
|
+
else
|
44
|
+
::Spec::Expectations.fail_with message
|
45
|
+
end
|
35
46
|
end
|
36
47
|
end
|
37
48
|
end
|
data/lib/spec/matchers/be.rb
CHANGED
@@ -41,12 +41,12 @@ module Spec
|
|
41
41
|
else
|
42
42
|
message = <<-MESSAGE
|
43
43
|
'should_not be #{@comparison_method} #{expected}' not only FAILED,
|
44
|
-
it
|
44
|
+
it is a bit confusing.
|
45
45
|
MESSAGE
|
46
46
|
|
47
47
|
raise message << ([:===,:==].include?(@comparison_method) ?
|
48
|
-
"
|
49
|
-
"
|
48
|
+
"It might be more clearly expressed without the \"be\"?" :
|
49
|
+
"It might be more clearly expressed in the positive?")
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -1,25 +1,5 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
-
|
4
|
-
class BeClose
|
5
|
-
def initialize(expected, delta)
|
6
|
-
@expected, @delta = expected, delta
|
7
|
-
end
|
8
|
-
|
9
|
-
def matches?(actual)
|
10
|
-
@actual = actual
|
11
|
-
(@actual - @expected).abs < @delta
|
12
|
-
end
|
13
|
-
|
14
|
-
def failure_message_for_should
|
15
|
-
"expected #{@expected} +/- (< #{@delta}), got #{@actual}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def description
|
19
|
-
"be close to #{@expected} (within +- #{@delta})"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
3
|
# :call-seq:
|
24
4
|
# should be_close(expected, delta)
|
25
5
|
# should_not be_close(expected, delta)
|
@@ -30,7 +10,23 @@ module Spec
|
|
30
10
|
#
|
31
11
|
# result.should be_close(3.0, 0.5)
|
32
12
|
def be_close(expected, delta)
|
33
|
-
|
13
|
+
Matcher.new :be_close, expected, delta do |expected, delta|
|
14
|
+
match do |actual|
|
15
|
+
(actual - expected).abs < delta
|
16
|
+
end
|
17
|
+
|
18
|
+
failure_message_for_should do |actual|
|
19
|
+
"expected #{expected} +/- (< #{delta}), got #{actual}"
|
20
|
+
end
|
21
|
+
|
22
|
+
failure_message_for_should_not do |actual|
|
23
|
+
"expected #{expected} +/- (< #{delta}), got #{actual}"
|
24
|
+
end
|
25
|
+
|
26
|
+
description do
|
27
|
+
"be close to #{expected} (within +- #{delta})"
|
28
|
+
end
|
29
|
+
end
|
34
30
|
end
|
35
31
|
end
|
36
32
|
end
|
@@ -1,28 +1,5 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
-
class BeInstanceOf
|
4
|
-
def initialize(expected)
|
5
|
-
@expected = expected
|
6
|
-
end
|
7
|
-
|
8
|
-
def matches?(actual)
|
9
|
-
@actual = actual
|
10
|
-
@actual.instance_of?(@expected)
|
11
|
-
end
|
12
|
-
|
13
|
-
def description
|
14
|
-
"be an instance of #{@expected}"
|
15
|
-
end
|
16
|
-
|
17
|
-
def failure_message_for_should
|
18
|
-
"expected instance of #{@expected}, got #{@actual.inspect}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def failure_message_for_should_not
|
22
|
-
"expected #{@actual.inspect} not to be an instance of #{@expected}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
3
|
# :call-seq:
|
27
4
|
# should be_instance_of(expected)
|
28
5
|
# should be_an_instance_of(expected)
|
@@ -36,10 +13,14 @@ module Spec
|
|
36
13
|
# 5.should be_instance_of(Fixnum)
|
37
14
|
# 5.should_not be_instance_of(Numeric)
|
38
15
|
# 5.should_not be_instance_of(Float)
|
39
|
-
def
|
40
|
-
|
16
|
+
def be_an_instance_of(expected)
|
17
|
+
Matcher.new :be_an_instance_of, expected do |expected|
|
18
|
+
match do |actual|
|
19
|
+
actual.instance_of?(expected)
|
20
|
+
end
|
21
|
+
end
|
41
22
|
end
|
42
23
|
|
43
|
-
alias_method :
|
24
|
+
alias_method :be_instance_of, :be_an_instance_of
|
44
25
|
end
|
45
26
|
end
|