rspec 1.2.8 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +41 -2
- data/Manifest.txt +11 -10
- data/Rakefile +47 -22
- data/Ruby1.9.rdoc +1 -2
- data/Upgrade.rdoc +56 -7
- data/bin/spec +2 -1
- data/cucumber.yml +3 -1
- data/examples/failing/README.txt +7 -3
- data/examples/failing/failing_implicit_docstrings_example.rb +0 -2
- data/examples/failing/mocking_example.rb +0 -2
- data/examples/failing/partial_mock_example.rb +0 -2
- data/examples/failing/pending_example.rb +0 -2
- data/examples/failing/predicate_example.rb +0 -2
- data/examples/failing/team_spec.rb +0 -3
- data/examples/failing/timeout_behaviour.rb +0 -2
- data/examples/passing/custom_formatter.rb +0 -1
- data/examples/passing/dynamic_spec.rb +0 -2
- data/examples/passing/file_accessor.rb +1 -2
- data/examples/passing/file_accessor_spec.rb +1 -2
- data/examples/passing/filtered_formatter.rb +0 -1
- data/examples/passing/greeter_spec.rb +0 -1
- data/examples/passing/helper_method_example.rb +0 -2
- data/examples/passing/implicit_docstrings_example.rb +0 -2
- data/examples/passing/io_processor_spec.rb +1 -2
- data/examples/passing/mocking_example.rb +0 -2
- data/examples/passing/nested_classes_example.rb +1 -2
- data/examples/passing/options_example.rb +0 -2
- data/examples/passing/partial_mock_example.rb +0 -2
- data/examples/passing/pending_example.rb +0 -2
- data/examples/passing/predicate_example.rb +0 -2
- data/examples/passing/shared_example_group_example.rb +0 -2
- data/examples/passing/simple_matcher_example.rb +0 -2
- data/examples/passing/stack_spec.rb +2 -3
- data/examples/passing/stack_spec_with_nested_example_groups.rb +2 -3
- data/examples/passing/stubbing_example.rb +0 -2
- data/examples/passing/yielding_example.rb +0 -2
- data/features/before_and_after_blocks/before_and_after_blocks.feature +4 -4
- data/features/command_line/line_number_option.feature +14 -14
- data/features/command_line/line_number_option_with_example_with_no_name.feature +2 -2
- data/features/example_groups/define_example_attribute.feature +41 -0
- data/features/example_groups/example_group_with_should_methods.feature +1 -1
- data/features/example_groups/implicit_docstrings.feature +7 -7
- data/features/example_groups/nested_groups.feature +2 -2
- data/features/expectations/customized_message.feature +4 -4
- data/features/expectations/expect_change.feature +4 -4
- data/features/expectations/expect_error.feature +4 -4
- data/features/extensions/custom_example_group.feature +10 -10
- data/features/formatters/custom_formatter.feature +3 -3
- data/features/interop/examples_and_tests_together.feature +10 -6
- data/features/interop/rspec_output.feature +1 -1
- data/features/interop/test_case_with_should_methods.feature +1 -1
- data/features/load_paths/add_lib_to_load_path.feature +20 -0
- data/features/load_paths/add_spec_to_load_path.feature +20 -0
- data/features/matchers/define_diffable_matcher.feature +2 -2
- data/features/matchers/define_matcher.feature +19 -19
- data/features/matchers/define_matcher_outside_rspec.feature +2 -3
- data/features/matchers/define_matcher_with_fluent_interface.feature +2 -2
- data/features/matchers/define_wrapped_matcher.feature +29 -0
- data/features/mock_framework_integration/use_flexmock.feature +1 -1
- data/features/mock_framework_integration/use_mocha.feature +1 -1
- data/features/mock_framework_integration/use_rr.feature +1 -1
- data/features/mocks/mix_stubs_and_mocks.feature +2 -2
- data/features/mocks/stub_implementation.feature +1 -1
- data/features/pending/pending_examples.feature +16 -16
- data/features/runner/specify_line_number.feature +4 -4
- data/features/spec_helper/spec_helper.feature +25 -0
- data/features/step_definitions/running_rspec_steps.rb +4 -2
- data/features/subject/explicit_subject.feature +2 -2
- data/features/subject/implicit_subject.feature +14 -2
- data/features/support/env.rb +6 -3
- data/lib/spec/adapters/mock_frameworks/mocha.rb +6 -1
- data/lib/spec/example/example_group_methods.rb +7 -0
- data/lib/spec/example/example_methods.rb +1 -1
- data/lib/spec/example/subject.rb +8 -0
- data/lib/spec/interop/test.rb +27 -1
- data/lib/spec/interop/test/unit/testcase.rb +1 -1
- data/lib/spec/matchers/exist.rb +2 -2
- data/lib/spec/matchers/extensions/instance_exec.rb +28 -20
- data/lib/spec/matchers/matcher.rb +21 -20
- data/lib/spec/mocks/argument_matchers.rb +17 -13
- data/lib/spec/mocks/error_generator.rb +14 -3
- data/lib/spec/mocks/{spec_methods.rb → example_methods.rb} +25 -11
- data/lib/spec/mocks/framework.rb +1 -1
- data/lib/spec/mocks/methods.rb +15 -0
- data/lib/spec/mocks/mock.rb +16 -10
- data/lib/spec/mocks/proxy.rb +1 -1
- data/lib/spec/rake/spectask.rb +3 -3
- data/lib/spec/runner/backtrace_tweaker.rb +41 -22
- data/lib/spec/runner/configuration.rb +18 -1
- data/lib/spec/runner/differs/default.rb +1 -1
- data/lib/spec/runner/drb_command_line.rb +5 -2
- data/lib/spec/runner/formatter/base_text_formatter.rb +8 -3
- data/lib/spec/runner/option_parser.rb +21 -15
- data/lib/spec/runner/options.rb +54 -23
- data/lib/spec/version.rb +3 -3
- data/resources/helpers/cmdline.rb +0 -1
- data/spec/autotest/autotest_helper.rb +4 -6
- data/spec/autotest/discover_spec.rb +2 -2
- data/spec/autotest/failed_results_re_spec.rb +1 -1
- data/spec/autotest/rspec_spec.rb +1 -1
- data/spec/spec/dsl/main_spec.rb +1 -1
- data/spec/spec/example/example_group_class_definition_spec.rb +1 -1
- data/spec/spec/example/example_group_factory_spec.rb +1 -1
- data/spec/spec/example/example_group_methods_spec.rb +21 -1
- data/spec/spec/example/example_group_proxy_spec.rb +1 -1
- data/spec/spec/example/example_group_spec.rb +1 -1
- data/spec/spec/example/example_matcher_spec.rb +1 -1
- data/spec/spec/example/example_methods_spec.rb +1 -1
- data/spec/spec/example/example_proxy_spec.rb +1 -1
- data/spec/spec/example/helper_method_spec.rb +1 -1
- data/spec/spec/example/nested_example_group_spec.rb +1 -1
- data/spec/spec/example/predicate_matcher_spec.rb +1 -1
- data/spec/spec/example/shared_example_group_spec.rb +1 -1
- data/spec/spec/example/subclassing_example_group_spec.rb +1 -1
- data/spec/spec/example/subject_spec.rb +17 -1
- data/spec/spec/expectations/differs/default_spec.rb +16 -3
- data/spec/spec/expectations/extensions/kernel_spec.rb +1 -1
- data/spec/spec/expectations/fail_with_spec.rb +1 -1
- data/spec/spec/expectations/handler_spec.rb +1 -1
- data/spec/spec/expectations/wrap_expectation_spec.rb +1 -1
- data/spec/spec/interop/test/unit/resources/test_case_with_various_names.rb +22 -0
- data/spec/spec/interop/test/unit/spec_spec.rb +1 -1
- data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +2 -2
- data/spec/spec/interop/test/unit/testcase_spec.rb +7 -2
- data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +1 -1
- data/spec/spec/matchers/be_close_spec.rb +1 -1
- data/spec/spec/matchers/be_instance_of_spec.rb +1 -1
- data/spec/spec/matchers/be_kind_of_spec.rb +1 -1
- data/spec/spec/matchers/be_spec.rb +13 -1
- data/spec/spec/matchers/change_spec.rb +1 -1
- data/spec/spec/matchers/compatibility_spec.rb +1 -1
- data/spec/spec/matchers/description_generation_spec.rb +1 -1
- data/spec/spec/matchers/dsl_spec.rb +1 -1
- data/spec/spec/matchers/eql_spec.rb +1 -1
- data/spec/spec/matchers/equal_spec.rb +1 -1
- data/spec/spec/matchers/exist_spec.rb +6 -2
- data/spec/spec/matchers/has_spec.rb +19 -1
- data/spec/spec/matchers/have_spec.rb +1 -1
- data/spec/spec/matchers/include_spec.rb +1 -1
- data/spec/spec/matchers/match_array_spec.rb +1 -1
- data/spec/spec/matchers/match_spec.rb +1 -1
- data/spec/spec/matchers/matcher_methods_spec.rb +1 -1
- data/spec/spec/matchers/matcher_spec.rb +55 -28
- data/spec/spec/matchers/matchers_spec.rb +1 -1
- data/spec/spec/matchers/operator_matcher_spec.rb +1 -1
- data/spec/spec/matchers/raise_error_spec.rb +1 -1
- data/spec/spec/matchers/respond_to_spec.rb +1 -1
- data/spec/spec/matchers/satisfy_spec.rb +1 -1
- data/spec/spec/matchers/simple_matcher_spec.rb +1 -1
- data/spec/spec/matchers/throw_symbol_spec.rb +1 -1
- data/spec/spec/mocks/any_number_of_times_spec.rb +1 -1
- data/spec/spec/mocks/argument_expectation_spec.rb +1 -1
- data/spec/spec/mocks/argument_matchers_spec.rb +19 -0
- data/spec/spec/mocks/at_least_spec.rb +1 -1
- data/spec/spec/mocks/at_most_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_10260_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_10263_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_11545_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_15719_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_496_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_600_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_7611_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_7805_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_8165_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_8302_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_830_spec.rb +1 -1
- data/spec/spec/mocks/double_spec.rb +12 -0
- data/spec/spec/mocks/failing_argument_matchers_spec.rb +6 -6
- data/spec/spec/mocks/hash_including_matcher_spec.rb +1 -1
- data/spec/spec/mocks/hash_not_including_matcher_spec.rb +1 -1
- data/spec/spec/mocks/mock_ordering_spec.rb +4 -4
- data/spec/spec/mocks/mock_space_spec.rb +1 -1
- data/spec/spec/mocks/mock_spec.rb +20 -24
- data/spec/spec/mocks/multiple_return_value_spec.rb +8 -8
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +1 -1
- data/spec/spec/mocks/null_object_mock_spec.rb +1 -1
- data/spec/spec/mocks/once_counts_spec.rb +1 -1
- data/spec/spec/mocks/options_hash_spec.rb +1 -1
- data/spec/spec/mocks/partial_mock_spec.rb +1 -1
- data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +1 -1
- data/spec/spec/mocks/passing_argument_matchers_spec.rb +1 -1
- data/spec/spec/mocks/precise_counts_spec.rb +1 -1
- data/spec/spec/mocks/record_messages_spec.rb +1 -1
- data/spec/spec/mocks/stub_chain_spec.rb +1 -1
- data/spec/spec/mocks/stub_implementation_spec.rb +1 -1
- data/spec/spec/mocks/stub_spec.rb +14 -9
- data/spec/spec/mocks/stubbed_message_expectations_spec.rb +2 -2
- data/spec/spec/mocks/twice_counts_spec.rb +1 -1
- data/spec/spec/mocks/unstub_spec.rb +1 -1
- data/spec/spec/package/bin_spec_spec.rb +4 -10
- data/spec/spec/rake/spectask_spec.rb +2 -2
- data/spec/spec/runner/class_and_argument_parser_spec.rb +1 -1
- data/spec/spec/runner/command_line_spec.rb +1 -1
- data/spec/spec/runner/configuration_spec.rb +15 -6
- data/spec/spec/runner/drb_command_line_spec.rb +1 -1
- data/spec/spec/runner/example_group_runner_spec.rb +1 -1
- data/spec/spec/runner/formatter/base_formatter_spec.rb +1 -1
- data/spec/spec/runner/formatter/base_text_formatter_spec.rb +10 -1
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +1 -1
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +1 -1
- data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +72 -76
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +50 -50
- data/spec/spec/runner/formatter/html_formatted-1.8.7.html +50 -50
- data/spec/spec/runner/formatter/html_formatted-1.9.1.html +61 -69
- data/spec/spec/runner/formatter/html_formatter_spec.rb +26 -26
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +1 -1
- data/spec/spec/runner/formatter/profile_formatter_spec.rb +1 -1
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +13 -9
- data/spec/spec/runner/formatter/snippet_extractor_spec.rb +1 -1
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +1 -1
- data/spec/spec/runner/formatter/{text_mate_formatted-1.8.4.html → text_mate_formatted-1.8.6-jruby.html} +64 -59
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +46 -46
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +46 -46
- data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +55 -63
- data/spec/spec/runner/formatter/text_mate_formatter_spec.rb +3 -3
- data/spec/spec/runner/heckle_runner_spec.rb +1 -1
- data/spec/spec/runner/heckler_spec.rb +1 -1
- data/spec/spec/runner/line_number_query/line_number_query_fixture.rb +1 -1
- data/spec/spec/runner/line_number_query_spec.rb +10 -1
- data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +22 -16
- data/spec/spec/runner/option_parser_spec.rb +48 -14
- data/spec/spec/runner/options_spec.rb +16 -2
- data/spec/spec/runner/output_one_time_fixture.rb +1 -1
- data/spec/spec/runner/output_one_time_fixture_runner.rb +2 -3
- data/spec/spec/runner/output_one_time_spec.rb +6 -7
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +65 -22
- data/spec/spec/runner/reporter_spec.rb +1 -1
- data/spec/spec/runner_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -7
- data/spec/{spec → support}/spec_classes.rb +0 -0
- metadata +58 -17
- data/examples/failing/spec_helper.rb +0 -3
- data/examples/passing/spec_helper.rb +0 -3
- data/features/heckle/heckle.feature +0 -56
- data/spec/rspec_suite.rb +0 -6
- data/spec/spec/runner/formatter/html_formatted-1.8.4.html +0 -366
- data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +0 -387
- data/spec/spec/runner/formatter/html_formatted-1.8.5.html +0 -372
@@ -14,7 +14,7 @@ Feature: implicit subject
|
|
14
14
|
end
|
15
15
|
"""
|
16
16
|
When I run "spec top_level_subject_spec.rb"
|
17
|
-
Then the stdout should
|
17
|
+
Then the stdout should include "1 example, 0 failures"
|
18
18
|
|
19
19
|
Scenario: subject in a nested group
|
20
20
|
Given a file named "nested_subject_spec.rb" with:
|
@@ -28,4 +28,16 @@ Feature: implicit subject
|
|
28
28
|
end
|
29
29
|
"""
|
30
30
|
When I run "spec nested_subject_spec.rb"
|
31
|
-
Then the stdout should
|
31
|
+
Then the stdout should include "1 example, 0 failures"
|
32
|
+
|
33
|
+
Scenario: subject with getters
|
34
|
+
Given a file named "subject_with_getter_spec.rb" with:
|
35
|
+
"""
|
36
|
+
describe Array do
|
37
|
+
describe "when first created" do
|
38
|
+
its(:length) { should == 0 }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
"""
|
42
|
+
When I run "spec subject_with_getter_spec.rb"
|
43
|
+
Then the stdout should include "1 example, 0 failures"
|
data/features/support/env.rb
CHANGED
@@ -3,9 +3,8 @@ $:.unshift File.join(File.dirname(__FILE__), "/../../lib")
|
|
3
3
|
require 'spec/expectations'
|
4
4
|
require 'forwardable'
|
5
5
|
require 'tempfile'
|
6
|
-
require
|
7
|
-
require
|
8
|
-
|
6
|
+
require 'spec/ruby_forker'
|
7
|
+
require 'features/support/matchers/smart_match'
|
9
8
|
|
10
9
|
class RspecWorld
|
11
10
|
include Spec::Expectations
|
@@ -44,6 +43,10 @@ class RspecWorld
|
|
44
43
|
File.open(file_path, "w") { |f| f << contents }
|
45
44
|
end
|
46
45
|
|
46
|
+
def create_directory(dirname)
|
47
|
+
FileUtils.mkdir_p File.join(working_dir, dirname)
|
48
|
+
end
|
49
|
+
|
47
50
|
def last_stdout
|
48
51
|
@stdout
|
49
52
|
end
|
@@ -5,7 +5,12 @@ require 'mocha/object'
|
|
5
5
|
module Spec
|
6
6
|
module Adapters
|
7
7
|
module MockFramework
|
8
|
-
|
8
|
+
# Mocha::Standalone was deprecated as of Mocha 0.9.7.
|
9
|
+
begin
|
10
|
+
include Mocha::API
|
11
|
+
rescue NameError
|
12
|
+
include Mocha::Standalone
|
13
|
+
end
|
9
14
|
def setup_mocks_for_rspec
|
10
15
|
mocha_setup
|
11
16
|
end
|
@@ -165,6 +165,13 @@ module Spec
|
|
165
165
|
include mod if (Spec::Ruby.version.to_f >= 1.9) & (Module === mod) & !(Class === mod)
|
166
166
|
end
|
167
167
|
|
168
|
+
def let(name, &block)
|
169
|
+
define_method name do
|
170
|
+
@assignments ||= {}
|
171
|
+
@assignments[name] ||= instance_eval(&block)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
168
175
|
private
|
169
176
|
|
170
177
|
def subclass(*args, &example_group_block)
|
data/lib/spec/example/subject.rb
CHANGED
@@ -11,6 +11,7 @@ module Spec
|
|
11
11
|
# subject { CheckingAccount.new(:amount => 50, :currency => :USD) }
|
12
12
|
# it { should have_a_balance_of(50, :USD) }
|
13
13
|
# it { should_not be_overdrawn }
|
14
|
+
# its(:currency) { should == :USD }
|
14
15
|
# end
|
15
16
|
#
|
16
17
|
# See +ExampleMethods#should+ for more information about this approach.
|
@@ -18,6 +19,13 @@ module Spec
|
|
18
19
|
block.nil? ?
|
19
20
|
explicit_subject || implicit_subject : @explicit_subject_block = block
|
20
21
|
end
|
22
|
+
|
23
|
+
def its(attribute, &block)
|
24
|
+
describe(attribute) do
|
25
|
+
define_method(:subject) { super().send(attribute) }
|
26
|
+
it(&block)
|
27
|
+
end
|
28
|
+
end
|
21
29
|
|
22
30
|
attr_reader :explicit_subject_block # :nodoc:
|
23
31
|
|
data/lib/spec/interop/test.rb
CHANGED
@@ -1,10 +1,36 @@
|
|
1
1
|
require 'spec'
|
2
2
|
|
3
3
|
if Spec::Ruby.version.to_f >= 1.9
|
4
|
-
gem 'test-unit','1.2.3'
|
4
|
+
gem 'test-unit','= 1.2.3'
|
5
5
|
end
|
6
6
|
|
7
7
|
require 'test/unit'
|
8
|
+
|
9
|
+
if Spec::Ruby.version.to_f >= 1.9
|
10
|
+
require 'test/unit/version'
|
11
|
+
if Test::Unit::VERSION > '1.2.3'
|
12
|
+
raise <<-MESSAGE
|
13
|
+
#{'*' * 50}
|
14
|
+
Required: test-unit-1.2.3
|
15
|
+
Loaded: test-unit-#{Test::Unit::VERSION}
|
16
|
+
|
17
|
+
With ruby-1.9, rspec-#{Spec::VERSION::STRING} requires test-unit-1.2.3, and
|
18
|
+
tries to force it with "gem 'test-unit', '= 1.2.3'" in:
|
19
|
+
|
20
|
+
#{__FILE__}
|
21
|
+
|
22
|
+
Unfortunately, test-unit-#{Test::Unit::VERSION} was loaded anyway. While we are
|
23
|
+
aware of this bug we have not been able to track down its source.
|
24
|
+
Until we do, you have two alternatives:
|
25
|
+
|
26
|
+
* uninstall test-unit-2.0.3
|
27
|
+
* use 'script/spec' instead of 'rake spec'
|
28
|
+
#{'*' * 50}
|
29
|
+
MESSAGE
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
8
34
|
require 'test/unit/testresult'
|
9
35
|
|
10
36
|
require 'spec/interop/test/unit/testcase'
|
data/lib/spec/matchers/exist.rb
CHANGED
@@ -1,23 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
module Spec
|
2
|
+
module Matchers
|
3
|
+
module InstanceExec
|
4
|
+
unless respond_to?(:instance_exec)
|
5
|
+
# based on Bounded Spec InstanceExec (Mauricio Fernandez)
|
6
|
+
# http://eigenclass.org/hiki/bounded+space+instance_exec
|
7
|
+
# - uses singleton_class of matcher instead of global
|
8
|
+
# InstanceExecHelper module
|
9
|
+
# - this keeps it scoped to this class only, which is the
|
10
|
+
# only place we need it
|
11
|
+
# - only necessary for ruby 1.8.6
|
12
|
+
def instance_exec(*args, &block)
|
13
|
+
singleton_class = (class << self; self; end)
|
14
|
+
begin
|
15
|
+
orig_critical, Thread.critical = Thread.critical, true
|
16
|
+
n = 0
|
17
|
+
n += 1 while respond_to?(method_name="__instance_exec#{n}")
|
18
|
+
singleton_class.module_eval{ define_method(:__instance_exec, &block) }
|
19
|
+
ensure
|
20
|
+
Thread.critical = orig_critical
|
21
|
+
end
|
22
|
+
begin
|
23
|
+
return send(:__instance_exec, *args)
|
24
|
+
ensure
|
25
|
+
singleton_class.module_eval{ remove_method(:__instance_exec) } rescue nil
|
26
|
+
end
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
23
|
-
end
|
31
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
3
|
class Matcher
|
4
|
+
include Spec::Matchers::InstanceExec
|
4
5
|
include Spec::Matchers::Pretty
|
5
|
-
|
6
|
+
include Spec::Matchers
|
7
|
+
|
6
8
|
attr_reader :expected, :actual
|
7
|
-
|
9
|
+
|
8
10
|
def initialize(name, *expected, &declarations)
|
9
11
|
@name = name
|
10
12
|
@expected = expected
|
@@ -19,36 +21,35 @@ module Spec
|
|
19
21
|
instance_exec(*@expected, &declarations)
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
24
|
+
|
23
25
|
def matches?(actual)
|
24
|
-
@actual = actual
|
25
|
-
instance_exec(@actual, &@match_block)
|
26
|
+
instance_exec(@actual = actual, &@match_block)
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
def description(&block)
|
29
30
|
cache_or_call_cached(:description, &block)
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
def failure_message_for_should(&block)
|
33
|
-
cache_or_call_cached(:failure_message_for_should,
|
34
|
+
cache_or_call_cached(:failure_message_for_should, actual, &block)
|
34
35
|
end
|
35
|
-
|
36
|
+
|
36
37
|
def failure_message_for_should_not(&block)
|
37
|
-
cache_or_call_cached(:failure_message_for_should_not,
|
38
|
+
cache_or_call_cached(:failure_message_for_should_not, actual, &block)
|
38
39
|
end
|
39
|
-
|
40
|
+
|
40
41
|
def match(&block)
|
41
42
|
@match_block = block
|
42
43
|
end
|
43
|
-
|
44
|
+
|
44
45
|
def diffable?
|
45
46
|
@diffable
|
46
47
|
end
|
47
|
-
|
48
|
+
|
48
49
|
def diffable
|
49
50
|
@diffable = true
|
50
51
|
end
|
51
|
-
|
52
|
+
|
52
53
|
private
|
53
54
|
|
54
55
|
def making_declared_methods_public # :nodoc:
|
@@ -56,7 +57,7 @@ module Spec
|
|
56
57
|
# declared in the block eval'd by instance_exec in the block to which we
|
57
58
|
# are yielding here are scoped private. This is NOT the case for Ruby
|
58
59
|
# 1.8.7 or 1.9.
|
59
|
-
#
|
60
|
+
#
|
60
61
|
# Also, due some crazy scoping that I don't understand, these methods
|
61
62
|
# are actually available in the specs (something about the matcher being
|
62
63
|
# defined in the scope of Spec::Matchers or within an example), so not
|
@@ -69,18 +70,18 @@ module Spec
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def cache_or_call_cached(key, actual=nil, &block)
|
72
|
-
block ? @messages[key] = block :
|
73
|
+
block ? @messages[key] = block :
|
73
74
|
actual.nil? ? @messages[key].call : @messages[key].call(actual)
|
74
75
|
end
|
75
|
-
|
76
|
+
|
76
77
|
def name_to_sentence
|
77
78
|
split_words(@name)
|
78
79
|
end
|
79
|
-
|
80
|
+
|
80
81
|
def expected_to_sentence
|
81
82
|
to_sentence(@expected)
|
82
83
|
end
|
83
|
-
|
84
|
+
|
84
85
|
end
|
85
86
|
end
|
86
|
-
end
|
87
|
+
end
|
@@ -15,6 +15,12 @@ module Spec
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
class NoArgsMatcher
|
19
|
+
def description
|
20
|
+
"no args"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
18
24
|
class AnyArgMatcher
|
19
25
|
def initialize(ignore)
|
20
26
|
end
|
@@ -22,11 +28,9 @@ module Spec
|
|
22
28
|
def ==(other)
|
23
29
|
true
|
24
30
|
end
|
25
|
-
|
26
|
-
|
27
|
-
class NoArgsMatcher
|
31
|
+
|
28
32
|
def description
|
29
|
-
"
|
33
|
+
"anything"
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
@@ -138,6 +142,14 @@ module Spec
|
|
138
142
|
end
|
139
143
|
end
|
140
144
|
|
145
|
+
# :call-seq:
|
146
|
+
# object.should_receive(:message).with(no_args())
|
147
|
+
#
|
148
|
+
# Passes if no arguments are passed along with the message
|
149
|
+
def no_args
|
150
|
+
NoArgsMatcher.new
|
151
|
+
end
|
152
|
+
|
141
153
|
# :call-seq:
|
142
154
|
# object.should_receive(:message).with(any_args())
|
143
155
|
#
|
@@ -155,14 +167,6 @@ module Spec
|
|
155
167
|
AnyArgMatcher.new(nil)
|
156
168
|
end
|
157
169
|
|
158
|
-
# :call-seq:
|
159
|
-
# object.should_receive(:message).with(no_args)
|
160
|
-
#
|
161
|
-
# Passes if no arguments are passed along with the message
|
162
|
-
def no_args
|
163
|
-
NoArgsMatcher.new
|
164
|
-
end
|
165
|
-
|
166
170
|
# :call-seq:
|
167
171
|
# object.should_receive(:message).with(duck_type(:hello))
|
168
172
|
# object.should_receive(:message).with(duck_type(:hello, :goodbye))
|
@@ -221,7 +225,7 @@ module Spec
|
|
221
225
|
|
222
226
|
alias_method :a_kind_of, :kind_of
|
223
227
|
|
224
|
-
|
228
|
+
private
|
225
229
|
|
226
230
|
def anythingize_lonely_keys(*args)
|
227
231
|
hash = args.last.class == Hash ? args.delete_at(-1) : {}
|
@@ -3,7 +3,8 @@ module Spec
|
|
3
3
|
class ErrorGenerator
|
4
4
|
attr_writer :opts
|
5
5
|
|
6
|
-
def initialize(target, name)
|
6
|
+
def initialize(target, name, options={})
|
7
|
+
@declared_as = options[:__declared_as] || 'Mock'
|
7
8
|
@target = target
|
8
9
|
@name = name
|
9
10
|
end
|
@@ -19,7 +20,7 @@ module Spec
|
|
19
20
|
def raise_unexpected_message_args_error(expectation, *args)
|
20
21
|
expected_args = format_args(*expectation.expected_args)
|
21
22
|
actual_args = args.empty? ? "(no args)" : format_args(*args)
|
22
|
-
__raise "#{intro}
|
23
|
+
__raise "#{intro} received #{expectation.sym.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}"
|
23
24
|
end
|
24
25
|
|
25
26
|
def raise_expectation_error(sym, expected_received_count, actual_received_count, *args)
|
@@ -45,7 +46,17 @@ module Spec
|
|
45
46
|
private
|
46
47
|
|
47
48
|
def intro
|
48
|
-
|
49
|
+
if @name
|
50
|
+
"#{@declared_as} #{@name.inspect}"
|
51
|
+
elsif Mock === @target
|
52
|
+
@declared_as
|
53
|
+
elsif Class === @target
|
54
|
+
"<#{@target.inspect} (class)>"
|
55
|
+
elsif @target
|
56
|
+
@target
|
57
|
+
else
|
58
|
+
"nil"
|
59
|
+
end
|
49
60
|
end
|
50
61
|
|
51
62
|
def __raise(message)
|
@@ -6,7 +6,7 @@ module Spec
|
|
6
6
|
# Shortcut for creating an instance of Spec::Mocks::Mock.
|
7
7
|
#
|
8
8
|
# +name+ is used for failure reporting, so you should use the
|
9
|
-
# role that the
|
9
|
+
# role that the double is playing in the example.
|
10
10
|
#
|
11
11
|
# +stubs_and_options+ lets you assign options and stub values
|
12
12
|
# at the same time. The only option available is :null_object.
|
@@ -14,19 +14,33 @@ module Spec
|
|
14
14
|
#
|
15
15
|
# == Examples
|
16
16
|
#
|
17
|
-
#
|
18
|
-
#
|
17
|
+
# thing = double("thing", :a => "A")
|
18
|
+
# thing.a == "A" => true
|
19
19
|
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
20
|
+
# person = double("thing", :name => "Joe", :email => "joe@domain.com")
|
21
|
+
# person.name => "Joe"
|
22
|
+
# person.email => "joe@domain.com"
|
23
|
+
def double(*args)
|
24
|
+
__declare_double('Double', *args)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Alias for double
|
23
28
|
def mock(*args)
|
24
|
-
|
29
|
+
__declare_double('Mock', *args)
|
25
30
|
end
|
26
31
|
|
27
|
-
|
32
|
+
# Alias for double
|
33
|
+
def stub(*args)
|
34
|
+
__declare_double('Stub', *args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def __declare_double(declared_as, *args) # :nodoc:
|
38
|
+
args << {} unless Hash === args.last
|
39
|
+
args.last[:__declared_as] = declared_as
|
40
|
+
Spec::Mocks::Mock.new(*args)
|
41
|
+
end
|
28
42
|
|
29
|
-
# DEPRECATED - use
|
43
|
+
# DEPRECATED - use double('name').as_null_object instead
|
30
44
|
#
|
31
45
|
# Shortcut for creating a mock object that will return itself in response
|
32
46
|
# to any message it receives that it hasn't been explicitly instructed
|
@@ -35,8 +49,8 @@ module Spec
|
|
35
49
|
Spec.warn(<<-WARNING)
|
36
50
|
|
37
51
|
DEPRECATION: stub_everything('#{name}') is deprecated and will be removed
|
38
|
-
from a future version of rspec. Please use
|
39
|
-
or stub('#{name}').as_null_object instead.
|
52
|
+
from a future version of rspec. Please use double('#{name}').as_null_object
|
53
|
+
(or stub('#{name}').as_null_object or mock('#{name}').as_null_object instead.
|
40
54
|
|
41
55
|
WARNING
|
42
56
|
mock(name, :null_object => true)
|