rspec 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +125 -9
- data/EXAMPLES.rd +50 -27
- data/README +14 -1
- data/Rakefile +95 -42
- data/UPGRADE +31 -0
- data/bin/spec +0 -1
- data/bin/spec_translator +6 -0
- data/examples/auto_spec_description_example.rb +19 -0
- data/examples/{setup_teardown_example.rb → before_and_after_example.rb} +6 -6
- data/examples/behave_as_example.rb +45 -0
- data/examples/custom_expectation_matchers.rb +13 -12
- data/examples/dynamic_spec.rb +2 -2
- data/examples/file_accessor_spec.rb +2 -2
- data/examples/greeter_spec.rb +3 -3
- data/examples/helper_method_example.rb +2 -2
- data/examples/io_processor_spec.rb +4 -4
- data/examples/legacy_spec.rb +10 -0
- data/examples/mocking_example.rb +5 -5
- data/examples/multi_threaded_behaviour_runner.rb +25 -0
- data/examples/partial_mock_example.rb +4 -4
- data/examples/predicate_example.rb +4 -4
- data/examples/priority.txt +1 -0
- data/examples/shared_behaviours_example.rb +31 -0
- data/examples/stack_spec.rb +52 -69
- data/examples/stubbing_example.rb +10 -10
- data/examples/test_case_adapter_example.rb +26 -0
- data/examples/test_case_spec.rb +6 -6
- data/lib/spec.rb +9 -4
- data/lib/spec/dsl.rb +10 -0
- data/lib/spec/dsl/behaviour.rb +189 -0
- data/lib/spec/dsl/behaviour_callbacks.rb +43 -0
- data/lib/spec/dsl/behaviour_eval.rb +170 -0
- data/lib/spec/dsl/behaviour_factory.rb +32 -0
- data/lib/spec/dsl/composite_proc_builder.rb +28 -0
- data/lib/spec/dsl/configuration.rb +38 -0
- data/lib/spec/dsl/description.rb +34 -0
- data/lib/spec/dsl/example.rb +114 -0
- data/lib/spec/dsl/example_matcher.rb +28 -0
- data/lib/spec/{runner/spec_should_raise_handler.rb → dsl/example_should_raise_handler.rb} +4 -4
- data/lib/spec/expectations.rb +0 -3
- data/lib/spec/expectations/differs/default.rb +0 -1
- data/lib/spec/expectations/extensions.rb +0 -1
- data/lib/spec/expectations/extensions/object.rb +10 -53
- data/lib/spec/expectations/handler.rb +14 -18
- data/lib/spec/extensions.rb +1 -0
- data/lib/spec/extensions/object.rb +6 -0
- data/lib/spec/matchers.rb +19 -21
- data/lib/spec/matchers/be.rb +40 -11
- data/lib/spec/matchers/be_close.rb +2 -2
- data/lib/spec/matchers/operator_matcher.rb +52 -0
- data/lib/spec/matchers/respond_to.rb +21 -11
- data/lib/spec/mocks.rb +5 -28
- data/lib/spec/mocks/argument_constraint_matchers.rb +12 -0
- data/lib/spec/mocks/argument_expectation.rb +7 -4
- data/lib/spec/mocks/methods.rb +11 -16
- data/lib/spec/mocks/mock.rb +6 -3
- data/lib/spec/mocks/{mock_handler.rb → proxy.rb} +4 -7
- data/lib/spec/mocks/space.rb +28 -0
- data/lib/spec/mocks/spec_methods.rb +30 -0
- data/lib/spec/rake/spectask.rb +23 -21
- data/lib/spec/rake/verify_rcov.rb +1 -0
- data/lib/spec/runner.rb +88 -35
- data/lib/spec/runner/backtrace_tweaker.rb +2 -1
- data/lib/spec/runner/behaviour_runner.rb +102 -0
- data/lib/spec/runner/command_line.rb +5 -17
- data/lib/spec/runner/drb_command_line.rb +2 -2
- data/lib/spec/runner/extensions/kernel.rb +22 -9
- data/lib/spec/runner/formatter.rb +4 -0
- data/lib/spec/runner/formatter/base_formatter.rb +63 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +22 -52
- data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +25 -0
- data/lib/spec/runner/formatter/failing_examples_formatter.rb +22 -0
- data/lib/spec/runner/formatter/html_formatter.rb +74 -29
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +6 -8
- data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
- data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +6 -6
- data/lib/spec/runner/heckle_runner.rb +8 -7
- data/lib/spec/runner/option_parser.rb +136 -55
- data/lib/spec/runner/options.rb +26 -0
- data/lib/spec/runner/reporter.rb +38 -31
- data/lib/spec/runner/spec_parser.rb +22 -13
- data/lib/spec/test_case_adapter.rb +10 -0
- data/lib/spec/translator.rb +103 -86
- data/lib/spec/version.rb +7 -15
- data/plugins/mock_frameworks/flexmock.rb +27 -0
- data/plugins/mock_frameworks/mocha.rb +21 -0
- data/plugins/mock_frameworks/rspec.rb +18 -0
- data/spec/spec/dsl/behaviour_eval_spec.rb +49 -0
- data/spec/spec/dsl/behaviour_factory_spec.rb +30 -0
- data/spec/spec/dsl/behaviour_spec.rb +508 -0
- data/spec/spec/dsl/composite_proc_builder_spec.rb +57 -0
- data/spec/spec/dsl/configuration_spec.rb +43 -0
- data/spec/spec/dsl/description_spec.rb +51 -0
- data/spec/spec/dsl/example_class_spec.rb +24 -0
- data/spec/spec/dsl/example_instance_spec.rb +140 -0
- data/spec/spec/dsl/example_should_raise_spec.rb +137 -0
- data/spec/spec/dsl/predicate_matcher_spec.rb +21 -0
- data/spec/spec/dsl/shared_behaviour_spec.rb +186 -0
- data/spec/spec/expectations/differs/default_spec.rb +12 -12
- data/spec/spec/expectations/extensions/object_spec.rb +10 -10
- data/spec/spec/expectations/fail_with_spec.rb +20 -20
- data/spec/spec/matchers/be_close_spec.rb +37 -31
- data/spec/spec/matchers/be_spec.rb +50 -41
- data/spec/spec/matchers/change_spec.rb +54 -54
- data/spec/spec/matchers/description_generation_spec.rb +43 -31
- data/spec/spec/matchers/eql_spec.rb +24 -37
- data/spec/spec/matchers/equal_spec.rb +24 -37
- data/spec/spec/matchers/exist_spec.rb +48 -0
- data/spec/spec/matchers/handler_spec.rb +36 -23
- data/spec/spec/matchers/has_spec.rb +8 -8
- data/spec/spec/matchers/have_spec.rb +38 -38
- data/spec/spec/matchers/include_spec.rb +6 -6
- data/spec/spec/matchers/match_spec.rb +8 -8
- data/spec/spec/matchers/matcher_methods_spec.rb +24 -31
- data/spec/spec/matchers/raise_error_spec.rb +34 -34
- data/spec/spec/matchers/respond_to_spec.rb +32 -8
- data/spec/spec/matchers/satisfy_spec.rb +6 -6
- data/spec/spec/matchers/should_===_spec.rb +38 -0
- data/spec/spec/matchers/should_==_spec.rb +37 -0
- data/spec/spec/matchers/should_=~_spec.rb +36 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +47 -55
- data/spec/spec/mocks/any_number_of_times_spec.rb +16 -21
- data/spec/spec/mocks/argument_expectation_spec.rb +3 -3
- data/spec/spec/mocks/at_least_spec.rb +30 -30
- data/spec/spec/mocks/at_most_spec.rb +53 -57
- data/spec/spec/mocks/bug_report_10260_spec.rb +8 -0
- data/spec/spec/mocks/bug_report_7611_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_7805_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_8165_spec.rb +5 -5
- data/spec/spec/mocks/bug_report_8302_spec.rb +5 -5
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +26 -27
- data/spec/spec/mocks/mock_ordering_spec.rb +19 -15
- data/spec/spec/mocks/mock_space_spec.rb +54 -0
- data/spec/spec/mocks/mock_spec.rb +111 -141
- data/spec/spec/mocks/multiple_return_value_spec.rb +48 -48
- data/spec/spec/mocks/null_object_mock_spec.rb +10 -10
- data/spec/spec/mocks/once_counts_spec.rb +32 -35
- data/spec/spec/mocks/options_hash_spec.rb +12 -10
- data/spec/spec/mocks/partial_mock_spec.rb +15 -15
- data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +24 -22
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +19 -19
- data/spec/spec/mocks/precise_counts_spec.rb +28 -32
- data/spec/spec/mocks/record_messages_spec.rb +10 -10
- data/spec/spec/mocks/stub_spec.rb +45 -45
- data/spec/spec/mocks/twice_counts_spec.rb +21 -21
- data/spec/spec/package/bin_spec_spec.rb +12 -0
- data/spec/spec/runner/behaviour_runner_spec.rb +114 -0
- data/spec/spec/runner/command_line_spec.rb +8 -8
- data/spec/spec/runner/context_matching_spec.rb +14 -15
- data/spec/spec/runner/drb_command_line_spec.rb +12 -12
- data/spec/spec/runner/execution_context_spec.rb +8 -29
- data/spec/spec/runner/extensions/kernel_spec.rb +36 -0
- data/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb +27 -0
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +28 -0
- data/spec/spec/runner/formatter/html_formatter_spec.rb +9 -8
- data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +6 -6
- data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +10 -10
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +22 -27
- data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +6 -5
- data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +17 -17
- data/spec/spec/runner/formatter/snippet_extractor_spec.rb +11 -0
- data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +6 -6
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +17 -17
- data/spec/spec/runner/heckle_runner_spec.rb +21 -21
- data/spec/spec/runner/heckler_spec.rb +5 -5
- data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +12 -12
- data/spec/spec/runner/object_ext_spec.rb +3 -3
- data/spec/spec/runner/option_parser_spec.rb +171 -102
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +21 -12
- data/spec/spec/runner/reporter_spec.rb +106 -97
- data/spec/spec/runner/spec_matcher_spec.rb +46 -51
- data/spec/spec/runner/spec_parser_spec.rb +72 -16
- data/spec/spec/spec_classes.rb +12 -3
- data/spec/spec/translator_spec.rb +165 -36
- metadata +66 -76
- data/RELEASE-PLAN +0 -117
- data/examples/auto_spec_name_generation_example.rb +0 -18
- data/lib/spec/callback.rb +0 -11
- data/lib/spec/callback/callback_container.rb +0 -60
- data/lib/spec/callback/extensions/module.rb +0 -24
- data/lib/spec/callback/extensions/object.rb +0 -37
- data/lib/spec/deprecated.rb +0 -3
- data/lib/spec/expectations/extensions/proc.rb +0 -57
- data/lib/spec/expectations/should.rb +0 -5
- data/lib/spec/expectations/should/base.rb +0 -64
- data/lib/spec/expectations/should/change.rb +0 -69
- data/lib/spec/expectations/should/have.rb +0 -128
- data/lib/spec/expectations/should/not.rb +0 -74
- data/lib/spec/expectations/should/should.rb +0 -81
- data/lib/spec/expectations/sugar.rb +0 -47
- data/lib/spec/runner/context.rb +0 -154
- data/lib/spec/runner/context_eval.rb +0 -142
- data/lib/spec/runner/context_runner.rb +0 -55
- data/lib/spec/runner/execution_context.rb +0 -17
- data/lib/spec/runner/spec_matcher.rb +0 -25
- data/lib/spec/runner/specification.rb +0 -114
- data/spec/spec/callback/callback_container_spec.rb +0 -27
- data/spec/spec/callback/module_spec.rb +0 -37
- data/spec/spec/callback/object_spec.rb +0 -90
- data/spec/spec/callback/object_with_class_callback_spec.rb +0 -19
- data/spec/spec/expectations/should/should_==_spec.rb +0 -19
- data/spec/spec/expectations/should/should_=~_spec.rb +0 -13
- data/spec/spec/expectations/should/should_be_a_kind_of_spec.rb +0 -21
- data/spec/spec/expectations/should/should_be_an_instance_of_spec.rb +0 -30
- data/spec/spec/expectations/should/should_be_arbitrary_predicate_spec.rb +0 -81
- data/spec/spec/expectations/should/should_be_close_spec.rb +0 -18
- data/spec/spec/expectations/should/should_be_comparison_operator_spec.rb +0 -44
- data/spec/spec/expectations/should/should_be_false_spec.rb +0 -39
- data/spec/spec/expectations/should/should_be_spec.rb +0 -11
- data/spec/spec/expectations/should/should_be_true_spec.rb +0 -27
- data/spec/spec/expectations/should/should_change_spec.rb +0 -184
- data/spec/spec/expectations/should/should_eql_spec.rb +0 -11
- data/spec/spec/expectations/should/should_equal_spec.rb +0 -11
- data/spec/spec/expectations/should/should_have_at_least_spec.rb +0 -53
- data/spec/spec/expectations/should/should_have_at_most_spec.rb +0 -45
- data/spec/spec/expectations/should/should_have_key_spec.rb +0 -21
- data/spec/spec/expectations/should/should_have_spec.rb +0 -64
- data/spec/spec/expectations/should/should_include_spec.rb +0 -59
- data/spec/spec/expectations/should/should_match_spec.rb +0 -25
- data/spec/spec/expectations/should/should_not_==_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_be_a_kind_of_spec.rb +0 -21
- data/spec/spec/expectations/should/should_not_be_an_instance_of_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_be_arbitrary_predicate_spec.rb +0 -68
- data/spec/spec/expectations/should/should_not_be_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_change_spec.rb +0 -24
- data/spec/spec/expectations/should/should_not_eql_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_equal_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_have_key_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_include_spec.rb +0 -58
- data/spec/spec/expectations/should/should_not_match_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_raise_spec.rb +0 -75
- data/spec/spec/expectations/should/should_not_respond_to_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_throw_spec.rb +0 -35
- data/spec/spec/expectations/should/should_raise_spec.rb +0 -66
- data/spec/spec/expectations/should/should_respond_to_spec.rb +0 -15
- data/spec/spec/expectations/should/should_satisfy_spec.rb +0 -35
- data/spec/spec/expectations/should/should_throw_spec.rb +0 -27
- data/spec/spec/runner/context_runner_spec.rb +0 -100
- data/spec/spec/runner/context_spec.rb +0 -405
- data/spec/spec/runner/kernel_ext_spec.rb +0 -16
- data/spec/spec/runner/spec_name_generation_spec.rb +0 -102
- data/spec/spec/runner/specification_class_spec.rb +0 -72
- data/spec/spec/runner/specification_instance_spec.rb +0 -160
- data/spec/spec/runner/specification_should_raise_spec.rb +0 -136
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
module Spec
|
|
2
2
|
module Mocks
|
|
3
|
-
class
|
|
3
|
+
class Proxy
|
|
4
4
|
DEFAULT_OPTIONS = {
|
|
5
5
|
:null_object => false,
|
|
6
|
-
:auto_verify => true
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
def initialize(target, name, options={})
|
|
@@ -84,12 +83,10 @@ module Spec
|
|
|
84
83
|
@error_generator.raise_unexpected_message_error sym, *args
|
|
85
84
|
end
|
|
86
85
|
|
|
87
|
-
|
|
86
|
+
private
|
|
88
87
|
|
|
89
88
|
def __add(expected_from, sym, block)
|
|
90
|
-
|
|
91
|
-
current_spec = Runner::Specification.current
|
|
92
|
-
current_spec.after_teardown {verify} if current_spec && @options[:auto_verify]
|
|
89
|
+
$rspec_mocks.add(@target)
|
|
93
90
|
define_expected_method(sym)
|
|
94
91
|
end
|
|
95
92
|
|
|
@@ -101,7 +98,7 @@ module Spec
|
|
|
101
98
|
|
|
102
99
|
metaclass_eval(<<-EOF, __FILE__, __LINE__)
|
|
103
100
|
def #{sym}(*args, &block)
|
|
104
|
-
|
|
101
|
+
__mock_proxy.message_received :#{sym}, *args, &block
|
|
105
102
|
end
|
|
106
103
|
EOF
|
|
107
104
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Spec
|
|
2
|
+
module Mocks
|
|
3
|
+
class Space
|
|
4
|
+
def add(obj)
|
|
5
|
+
mocks << obj unless mocks.include?(obj)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def verify_all
|
|
9
|
+
mocks.each do |mock|
|
|
10
|
+
mock.rspec_verify
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def reset_all
|
|
15
|
+
mocks.each do |mock|
|
|
16
|
+
mock.rspec_reset
|
|
17
|
+
end
|
|
18
|
+
mocks.clear
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def mocks
|
|
24
|
+
@mocks ||= []
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Spec
|
|
2
|
+
module Mocks
|
|
3
|
+
module SpecMethods
|
|
4
|
+
include Spec::Mocks::ArgumentConstraintMatchers
|
|
5
|
+
|
|
6
|
+
# Shortcut for creating an instance of Spec::Mocks::Mock.
|
|
7
|
+
def mock(name, options={})
|
|
8
|
+
Spec::Mocks::Mock.new(name, options)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Shortcut for creating an instance of Spec::Mocks::Mock with
|
|
12
|
+
# predefined method stubs.
|
|
13
|
+
#
|
|
14
|
+
# == Examples
|
|
15
|
+
#
|
|
16
|
+
# stub_thing = stub("thing", :a => "A")
|
|
17
|
+
# stub_thing.a == "A" => true
|
|
18
|
+
#
|
|
19
|
+
# stub_person = stub("thing", :name => "Joe", :email => "joe@domain.com")
|
|
20
|
+
# stub_person.name => "Joe"
|
|
21
|
+
# stub_person.email => "joe@domain.com"
|
|
22
|
+
def stub(name, stubs={})
|
|
23
|
+
object_stub = mock(name)
|
|
24
|
+
stubs.each { |key, value| object_stub.stub!(key).and_return(value) }
|
|
25
|
+
object_stub
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/spec/rake/spectask.rb
CHANGED
|
@@ -41,6 +41,7 @@ module Spec
|
|
|
41
41
|
attr_accessor :spec_opts
|
|
42
42
|
|
|
43
43
|
# Where RSpec's output is written. Defaults to STDOUT.
|
|
44
|
+
# DEPRECATED. Use --format FORMAT:WHERE in spec_opts.
|
|
44
45
|
attr_accessor :out
|
|
45
46
|
|
|
46
47
|
# Whether or not to use RCov (default is false)
|
|
@@ -103,31 +104,32 @@ module Spec
|
|
|
103
104
|
end
|
|
104
105
|
task @name do
|
|
105
106
|
RakeFileUtils.verbose(@verbose) do
|
|
106
|
-
ruby_opts = @ruby_opts.clone
|
|
107
|
-
ruby_opts.push( "-I\"#{lib_path}\"" )
|
|
108
|
-
ruby_opts.push( "-S rcov" ) if @rcov
|
|
109
|
-
ruby_opts.push( "-w" ) if @warning
|
|
110
|
-
|
|
111
|
-
redirect = @out.nil? ? "" : " > \"#{@out}\""
|
|
112
|
-
|
|
113
107
|
unless spec_file_list.empty?
|
|
114
108
|
# ruby [ruby_opts] -Ilib -S rcov [rcov_opts] bin/spec -- [spec_opts] examples
|
|
115
109
|
# or
|
|
116
110
|
# ruby [ruby_opts] -Ilib bin/spec [spec_opts] examples
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
111
|
+
cmd = "ruby "
|
|
112
|
+
|
|
113
|
+
ruby_opts = @ruby_opts.clone
|
|
114
|
+
ruby_opts << "-I\"#{lib_path}\""
|
|
115
|
+
ruby_opts << "-S rcov" if @rcov
|
|
116
|
+
ruby_opts << "-w" if @warning
|
|
117
|
+
cmd << ruby_opts.join(" ")
|
|
118
|
+
cmd << " "
|
|
119
|
+
cmd << rcov_option_list
|
|
120
|
+
cmd << %[ -o "#{@rcov_dir}" ] if @rcov
|
|
121
|
+
cmd << %Q|"#{spec_script}"|
|
|
122
|
+
cmd << " "
|
|
123
|
+
cmd << "-- " if @rcov
|
|
124
|
+
cmd << spec_file_list.collect { |fn| %["#{fn}"] }.join(' ')
|
|
125
|
+
cmd << " "
|
|
126
|
+
cmd << spec_option_list
|
|
127
|
+
cmd << " "
|
|
128
|
+
cmd << %Q| > "#{@out}"| if @out
|
|
129
|
+
|
|
130
|
+
unless system(cmd)
|
|
131
|
+
puts @failure_message if @failure_message
|
|
132
|
+
raise("Command #{cmd} failed") if @fail_on_error
|
|
131
133
|
end
|
|
132
134
|
end
|
|
133
135
|
end
|
data/lib/spec/runner.rb
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
1
|
require 'spec/runner/formatter'
|
|
2
|
-
require 'spec/runner/
|
|
3
|
-
require 'spec/runner/
|
|
4
|
-
require 'spec/runner/specification'
|
|
5
|
-
require 'spec/runner/execution_context'
|
|
6
|
-
require 'spec/runner/context_runner'
|
|
2
|
+
require 'spec/runner/behaviour_runner'
|
|
3
|
+
require 'spec/runner/options'
|
|
7
4
|
require 'spec/runner/option_parser'
|
|
8
5
|
require 'spec/runner/command_line'
|
|
9
6
|
require 'spec/runner/drb_command_line'
|
|
10
7
|
require 'spec/runner/backtrace_tweaker'
|
|
11
8
|
require 'spec/runner/reporter'
|
|
12
|
-
require 'spec/runner/spec_matcher'
|
|
13
9
|
require 'spec/runner/extensions/object'
|
|
14
10
|
require 'spec/runner/extensions/kernel'
|
|
15
|
-
require 'spec/runner/spec_should_raise_handler'
|
|
16
11
|
require 'spec/runner/spec_parser'
|
|
17
12
|
|
|
18
13
|
module Spec
|
|
19
|
-
# ==
|
|
14
|
+
# == Behaviours and Examples
|
|
20
15
|
#
|
|
21
|
-
# Rather than expressing examples in classes, RSpec uses a custom domain specific language to
|
|
22
|
-
#
|
|
16
|
+
# Rather than expressing examples in classes, RSpec uses a custom domain specific language to
|
|
17
|
+
# describe Behaviours and Examples of those behaviours.
|
|
23
18
|
#
|
|
24
|
-
# A
|
|
19
|
+
# A Behaviour is the equivalent of a fixture in xUnit-speak. It is a metaphor for the context
|
|
25
20
|
# in which you will run your executable example - a set of known objects in a known starting state.
|
|
21
|
+
# We begin be describing
|
|
26
22
|
#
|
|
27
|
-
#
|
|
23
|
+
# describe Account do
|
|
28
24
|
#
|
|
29
|
-
#
|
|
25
|
+
# before do
|
|
30
26
|
# @account = Account.new
|
|
31
27
|
# end
|
|
32
28
|
#
|
|
33
|
-
#
|
|
34
|
-
# @account.balance.
|
|
29
|
+
# it "should have a balance of $0" do
|
|
30
|
+
# @account.balance.should == Money.new(0, :dollars)
|
|
35
31
|
# end
|
|
36
32
|
#
|
|
37
33
|
# end
|
|
38
34
|
#
|
|
39
|
-
# We use the
|
|
35
|
+
# We use the before block to set up the Behaviour (given), and then the #it method to
|
|
40
36
|
# hold the example code that expresses the event (when) and the expected outcome (then).
|
|
41
37
|
#
|
|
42
38
|
# == Helper Methods
|
|
@@ -51,51 +47,52 @@ module Spec
|
|
|
51
47
|
#
|
|
52
48
|
# == Setup and Teardown
|
|
53
49
|
#
|
|
54
|
-
# You can use
|
|
50
|
+
# You can use before and after within a Behaviour. Both methods take an optional
|
|
51
|
+
# scope argument so you can run the block before :each example or before :all examples
|
|
55
52
|
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
53
|
+
# describe "..." do
|
|
54
|
+
# before :all do
|
|
58
55
|
# ...
|
|
59
56
|
# end
|
|
60
57
|
#
|
|
61
|
-
#
|
|
58
|
+
# before :each do
|
|
62
59
|
# ...
|
|
63
60
|
# end
|
|
64
61
|
#
|
|
65
|
-
#
|
|
62
|
+
# it "should do something" do
|
|
66
63
|
# ...
|
|
67
64
|
# end
|
|
68
65
|
#
|
|
69
|
-
#
|
|
66
|
+
# it "should do something else" do
|
|
70
67
|
# ...
|
|
71
68
|
# end
|
|
72
69
|
#
|
|
73
|
-
#
|
|
70
|
+
# after :each do
|
|
74
71
|
# ...
|
|
75
72
|
# end
|
|
76
73
|
#
|
|
77
|
-
#
|
|
74
|
+
# after :all do
|
|
78
75
|
# ...
|
|
79
76
|
# end
|
|
80
77
|
#
|
|
81
78
|
# end
|
|
82
79
|
#
|
|
83
|
-
# The <tt>
|
|
84
|
-
# the <tt>
|
|
80
|
+
# The <tt>before :each</tt> block will run before each of the examples, once for each example. Likewise,
|
|
81
|
+
# the <tt>after :each</tt> block will run after each of the examples.
|
|
85
82
|
#
|
|
86
|
-
# It is also possible to specify a <tt>
|
|
87
|
-
# block that will run only once for each
|
|
88
|
-
# and after the last <code>
|
|
89
|
-
# introduces dependencies between the
|
|
83
|
+
# It is also possible to specify a <tt>before :all</tt> and <tt>after :all</tt>
|
|
84
|
+
# block that will run only once for each behaviour, respectively before the first <code>before :each</code>
|
|
85
|
+
# and after the last <code>after :each</code>. The use of these is generally discouraged, because it
|
|
86
|
+
# introduces dependencies between the examples. Still, it might prove useful for very expensive operations
|
|
90
87
|
# if you know what you are doing.
|
|
91
88
|
#
|
|
92
89
|
# == Local helper methods
|
|
93
90
|
#
|
|
94
91
|
# You can include local helper methods by simply expressing them within a context:
|
|
95
92
|
#
|
|
96
|
-
#
|
|
93
|
+
# describe "..." do
|
|
97
94
|
#
|
|
98
|
-
#
|
|
95
|
+
# it "..." do
|
|
99
96
|
# helper_method
|
|
100
97
|
# end
|
|
101
98
|
#
|
|
@@ -116,17 +113,73 @@ module Spec
|
|
|
116
113
|
# end
|
|
117
114
|
# end
|
|
118
115
|
#
|
|
119
|
-
#
|
|
116
|
+
# describe "A new account" do
|
|
120
117
|
# include AccountExampleHelperMethods
|
|
121
|
-
#
|
|
118
|
+
# before do
|
|
122
119
|
# @account = Account.new
|
|
123
120
|
# end
|
|
124
121
|
#
|
|
125
|
-
#
|
|
122
|
+
# it "should have a balance of $0" do
|
|
126
123
|
# helper_method
|
|
127
124
|
# @account.balance.should eql(Money.new(0, :dollars))
|
|
128
125
|
# end
|
|
129
126
|
# end
|
|
127
|
+
#
|
|
128
|
+
# == Shared behaviour
|
|
129
|
+
#
|
|
130
|
+
# You can define a shared behaviour, that may be used on other behaviours
|
|
131
|
+
#
|
|
132
|
+
# describe "All Editions", :shared => true do
|
|
133
|
+
# it "all editions behaviour" ...
|
|
134
|
+
# end
|
|
135
|
+
#
|
|
136
|
+
# describe SmallEdition do
|
|
137
|
+
# it_should_behave_like "All Editions"
|
|
138
|
+
#
|
|
139
|
+
# it "should do small edition stuff" do
|
|
140
|
+
# ...
|
|
141
|
+
# end
|
|
142
|
+
# end
|
|
130
143
|
module Runner
|
|
144
|
+
class << self
|
|
145
|
+
def configuration # :nodoc:
|
|
146
|
+
@configuration ||= Spec::DSL::Configuration.new
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Use this to configure various configurable aspects of
|
|
150
|
+
# RSpec. For example, to choose a mock framework from
|
|
151
|
+
# RSpec, mocha and flexmock, you can do this:
|
|
152
|
+
#
|
|
153
|
+
# Spec::Runner.configure do |config|
|
|
154
|
+
# config.mock_with :rspec #or :mocha, or :flexmock
|
|
155
|
+
# end
|
|
156
|
+
#
|
|
157
|
+
# To use any other mock framework, you'll have to provide
|
|
158
|
+
# your own adapter. This is simply a module that responds to
|
|
159
|
+
# setup_mocks_for_rspec, verify_mocks_for_rspec and teardown_mocks_for_rspec.
|
|
160
|
+
# These are your hooks into the lifecycle of a given example. RSpec will
|
|
161
|
+
# call setup_mocks_for_rspec before running anything else in each Example.
|
|
162
|
+
# After executing the #after methods, RSpec will then call verify_mocks_for_rspec
|
|
163
|
+
# and teardown_mocks_for_rspec (this is guaranteed to run even if there are
|
|
164
|
+
# failures in verify_mocks_for_rspec).
|
|
165
|
+
#
|
|
166
|
+
# Once you've defined this module, you can pass that to mock_with:
|
|
167
|
+
#
|
|
168
|
+
# Spec::Runner.configure do |config|
|
|
169
|
+
# config.mock_with MyMockFrameworkAdapter
|
|
170
|
+
# end
|
|
171
|
+
#
|
|
172
|
+
# You can also configure the following items:
|
|
173
|
+
#
|
|
174
|
+
# # include SomeModule in every Behaviour
|
|
175
|
+
# config.include SomeModule
|
|
176
|
+
#
|
|
177
|
+
# # generate a do_something predicate_matcher for every Behaviour
|
|
178
|
+
# # - See Spec::DSL::Behaviour#predicate_matchers
|
|
179
|
+
# config.predicate_matchers[:does_something?] = :do_something
|
|
180
|
+
def configure
|
|
181
|
+
yield configuration
|
|
182
|
+
end
|
|
183
|
+
end
|
|
131
184
|
end
|
|
132
185
|
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
module Spec
|
|
2
|
+
module Runner
|
|
3
|
+
class BehaviourRunner
|
|
4
|
+
|
|
5
|
+
def initialize(options)
|
|
6
|
+
@behaviours = []
|
|
7
|
+
@options = options
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def add_behaviour(behaviour)
|
|
11
|
+
unless specified_examples.nil? || specified_examples.empty? #|| behaviour.matches?(specified_examples)
|
|
12
|
+
behaviour.retain_examples_matching!(specified_examples) #if behaviour.matches?(specified_examples)
|
|
13
|
+
end
|
|
14
|
+
@behaviours << behaviour unless behaviour.number_of_examples == 0
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Runs all contexts and returns the number of failures.
|
|
18
|
+
def run(paths, exit_when_done)
|
|
19
|
+
unless paths.nil? # It's nil when running single specs with ruby
|
|
20
|
+
paths = find_paths(paths)
|
|
21
|
+
sorted_paths = sort_paths(paths)
|
|
22
|
+
load_specs(sorted_paths)
|
|
23
|
+
end
|
|
24
|
+
@options.reporter.start(number_of_examples)
|
|
25
|
+
behaviours = @options.reverse ? @behaviours.reverse : @behaviours
|
|
26
|
+
begin
|
|
27
|
+
run_behaviours(behaviours)
|
|
28
|
+
rescue Interrupt
|
|
29
|
+
ensure
|
|
30
|
+
@options.reporter.end
|
|
31
|
+
end
|
|
32
|
+
failure_count = @options.reporter.dump
|
|
33
|
+
|
|
34
|
+
heckle if(failure_count == 0 && !@options.heckle_runner.nil?)
|
|
35
|
+
|
|
36
|
+
if(exit_when_done)
|
|
37
|
+
exit_code = (failure_count == 0) ? 0 : 1
|
|
38
|
+
exit(exit_code)
|
|
39
|
+
end
|
|
40
|
+
failure_count
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def run_behaviours(behaviours)
|
|
44
|
+
behaviours.each do |behaviour|
|
|
45
|
+
behaviour.run(@options.reporter, @options.dry_run, @options.reverse)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def number_of_examples
|
|
50
|
+
@behaviours.inject(0) {|sum, behaviour| sum + behaviour.number_of_examples}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
FILE_SORTERS = {
|
|
54
|
+
'mtime' => lambda {|file_a, file_b| File.mtime(file_b) <=> File.mtime(file_a)}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
def sorter(paths)
|
|
58
|
+
FILE_SORTERS[@options.loadby]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def sort_paths(paths)
|
|
62
|
+
sorter = sorter(paths)
|
|
63
|
+
paths = paths.sort(&sorter) unless sorter.nil?
|
|
64
|
+
paths
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def find_paths(paths)
|
|
70
|
+
result = []
|
|
71
|
+
paths.each do |path|
|
|
72
|
+
if File.directory?(path)
|
|
73
|
+
result += Dir["#{path}/**/*.rb"]
|
|
74
|
+
elsif File.file?(path)
|
|
75
|
+
result << path
|
|
76
|
+
else
|
|
77
|
+
raise "File or directory not found: #{path}"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
result
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def load_specs(paths)
|
|
84
|
+
paths.each do |path|
|
|
85
|
+
load path
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def specified_examples
|
|
90
|
+
@options.examples
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def heckle
|
|
94
|
+
heckle_runner = @options.heckle_runner
|
|
95
|
+
@options.heckle_runner = nil
|
|
96
|
+
behaviour_runner = self.class.new(@options)
|
|
97
|
+
behaviour_runner.instance_variable_set(:@behaviours, @behaviours)
|
|
98
|
+
heckle_runner.heckle_with(behaviour_runner)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|