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
|
@@ -2,24 +2,22 @@ module Spec
|
|
|
2
2
|
module Runner
|
|
3
3
|
module Formatter
|
|
4
4
|
class ProgressBarFormatter < BaseTextFormatter
|
|
5
|
-
def
|
|
6
|
-
@output.puts if first
|
|
7
|
-
STDOUT.flush
|
|
5
|
+
def add_behaviour(name)
|
|
8
6
|
end
|
|
9
7
|
|
|
10
|
-
def
|
|
8
|
+
def example_failed(name, counter, failure)
|
|
11
9
|
@output.print failure.expectation_not_met? ? red('F') : magenta('F')
|
|
12
|
-
|
|
10
|
+
@output.flush
|
|
13
11
|
end
|
|
14
12
|
|
|
15
|
-
def
|
|
13
|
+
def example_passed(name)
|
|
16
14
|
@output.print green('.')
|
|
17
|
-
|
|
15
|
+
@output.flush
|
|
18
16
|
end
|
|
19
17
|
|
|
20
18
|
def start_dump
|
|
21
19
|
@output.puts
|
|
22
|
-
|
|
20
|
+
@output.flush
|
|
23
21
|
end
|
|
24
22
|
end
|
|
25
23
|
end
|
|
@@ -2,19 +2,19 @@ module Spec
|
|
|
2
2
|
module Runner
|
|
3
3
|
module Formatter
|
|
4
4
|
class RdocFormatter < BaseTextFormatter
|
|
5
|
-
def
|
|
5
|
+
def add_behaviour(name)
|
|
6
6
|
@output.print "# #{name}\n"
|
|
7
|
-
|
|
7
|
+
@output.flush
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def
|
|
10
|
+
def example_passed(name)
|
|
11
11
|
@output.print "# * #{name}\n"
|
|
12
|
-
|
|
12
|
+
@output.flush
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def
|
|
15
|
+
def example_failed(name, counter, failure)
|
|
16
16
|
@output.print "# * #{name} [#{counter} - FAILED]\n"
|
|
17
|
-
|
|
17
|
+
@output.flush
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Spec
|
|
2
|
+
module Runner
|
|
3
|
+
module Formatter
|
|
4
|
+
# This class extracts code snippets by looking at the backtrace of the passed error
|
|
5
|
+
class SnippetExtractor #:nodoc:
|
|
6
|
+
class NullConverter; def convert(code, pre); code; end; end #:nodoc:
|
|
7
|
+
begin; require 'rubygems'; require 'syntax/convertors/html'; @@converter = Syntax::Convertors::HTML.for_syntax "ruby"; rescue LoadError => e; @@converter = NullConverter.new; end
|
|
8
|
+
|
|
9
|
+
def snippet(error)
|
|
10
|
+
raw_code, line = snippet_for(error.backtrace[0])
|
|
11
|
+
highlighted = @@converter.convert(raw_code, false)
|
|
12
|
+
highlighted << "\n<span class=\"comment\"># gem install syntax to get syntax highlighting</span>" if @@converter.is_a?(NullConverter)
|
|
13
|
+
post_process(highlighted, line)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def snippet_for(error_line)
|
|
17
|
+
if error_line =~ /(.*):(\d+)/
|
|
18
|
+
file = $1
|
|
19
|
+
line = $2.to_i
|
|
20
|
+
[lines_around(file, line), line]
|
|
21
|
+
else
|
|
22
|
+
["# Couldn't get snippet for #{error_line}", 1]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def lines_around(file, line)
|
|
27
|
+
if File.file?(file)
|
|
28
|
+
lines = File.open(file).read.split("\n")
|
|
29
|
+
min = [0, line-3].max
|
|
30
|
+
max = [line+1, lines.length-1].min
|
|
31
|
+
selected_lines = []
|
|
32
|
+
selected_lines.join("\n")
|
|
33
|
+
lines[min..max].join("\n")
|
|
34
|
+
else
|
|
35
|
+
"# Couldn't get snippet for #{file}"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def post_process(highlighted, offending_line)
|
|
40
|
+
new_lines = []
|
|
41
|
+
highlighted.split("\n").each_with_index do |line, i|
|
|
42
|
+
new_line = "<span class=\"linenum\">#{offending_line+i-2}</span>#{line}"
|
|
43
|
+
new_line = "<span class=\"offending\">#{new_line}</span>" if i == 2
|
|
44
|
+
new_lines << new_line
|
|
45
|
+
end
|
|
46
|
+
new_lines.join("\n")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -2,20 +2,20 @@ module Spec
|
|
|
2
2
|
module Runner
|
|
3
3
|
module Formatter
|
|
4
4
|
class SpecdocFormatter < BaseTextFormatter
|
|
5
|
-
def
|
|
5
|
+
def add_behaviour(name)
|
|
6
6
|
@output.puts
|
|
7
7
|
@output.puts name
|
|
8
|
-
|
|
8
|
+
@output.flush
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def
|
|
11
|
+
def example_failed(name, counter, failure)
|
|
12
12
|
@output.puts failure.expectation_not_met? ? red("- #{name} (FAILED - #{counter})") : magenta("- #{name} (ERROR - #{counter})")
|
|
13
|
-
|
|
13
|
+
@output.flush
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def
|
|
16
|
+
def example_passed(name)
|
|
17
17
|
@output.print green("- #{name}\n")
|
|
18
|
-
|
|
18
|
+
@output.flush
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -13,9 +13,9 @@ module Spec
|
|
|
13
13
|
@heckle_class = heckle_class
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
# Runs all the contexts held by +
|
|
16
|
+
# Runs all the contexts held by +behaviour_runner+ once for each of the
|
|
17
17
|
# methods in the matched classes.
|
|
18
|
-
def heckle_with(
|
|
18
|
+
def heckle_with(behaviour_runner)
|
|
19
19
|
if @filter =~ /(.*)[#\.](.*)/
|
|
20
20
|
heckle_method($1, $2)
|
|
21
21
|
else
|
|
@@ -25,7 +25,7 @@ module Spec
|
|
|
25
25
|
|
|
26
26
|
def heckle_method(class_name, method_name)
|
|
27
27
|
verify_constant(class_name)
|
|
28
|
-
heckle = @heckle_class.new(class_name, method_name,
|
|
28
|
+
heckle = @heckle_class.new(class_name, method_name, behaviour_runner)
|
|
29
29
|
heckle.validate
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -39,7 +39,7 @@ module Spec
|
|
|
39
39
|
|
|
40
40
|
classes.each do |klass|
|
|
41
41
|
klass.instance_methods(false).each do |method_name|
|
|
42
|
-
heckle = @heckle_class.new(klass.name, method_name,
|
|
42
|
+
heckle = @heckle_class.new(klass.name, method_name, behaviour_runner)
|
|
43
43
|
heckle.validate
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -57,13 +57,14 @@ module Spec
|
|
|
57
57
|
|
|
58
58
|
#Supports Heckle 1.2 and prior (earlier versions used Heckle::Base)
|
|
59
59
|
class Heckler < (Heckle.const_defined?(:Base) ? Heckle::Base : Heckle)
|
|
60
|
-
def initialize(klass_name, method_name,
|
|
60
|
+
def initialize(klass_name, method_name, behaviour_runner)
|
|
61
61
|
super(klass_name, method_name)
|
|
62
|
-
@
|
|
62
|
+
@behaviour_runner = behaviour_runner
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def tests_pass?
|
|
66
|
-
|
|
66
|
+
paths = [] # We can pass an empty array of paths - our specs are already loaded.
|
|
67
|
+
failure_count = @behaviour_runner.run(paths, false)
|
|
67
68
|
failure_count == 0
|
|
68
69
|
end
|
|
69
70
|
end
|
|
@@ -1,27 +1,40 @@
|
|
|
1
|
-
require 'ostruct'
|
|
2
1
|
require 'optparse'
|
|
3
|
-
require '
|
|
4
|
-
require 'spec/runner/formatter'
|
|
5
|
-
require 'spec/runner/backtrace_tweaker'
|
|
6
|
-
require 'spec/runner/reporter'
|
|
7
|
-
require 'spec/runner/context_runner'
|
|
2
|
+
require 'stringio'
|
|
8
3
|
|
|
9
4
|
module Spec
|
|
10
5
|
module Runner
|
|
11
6
|
class OptionParser
|
|
7
|
+
BUILT_IN_FORMATTERS = {
|
|
8
|
+
'specdoc' => Formatter::SpecdocFormatter,
|
|
9
|
+
's' => Formatter::SpecdocFormatter,
|
|
10
|
+
'html' => Formatter::HtmlFormatter,
|
|
11
|
+
'h' => Formatter::HtmlFormatter,
|
|
12
|
+
'rdoc' => Formatter::RdocFormatter,
|
|
13
|
+
'r' => Formatter::RdocFormatter,
|
|
14
|
+
'progress' => Formatter::ProgressBarFormatter,
|
|
15
|
+
'p' => Formatter::ProgressBarFormatter,
|
|
16
|
+
'failing_examples' => Formatter::FailingExamplesFormatter,
|
|
17
|
+
'e' => Formatter::FailingExamplesFormatter,
|
|
18
|
+
'failing_behaviours' => Formatter::FailingBehavioursFormatter,
|
|
19
|
+
'b' => Formatter::FailingBehavioursFormatter
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
def initialize
|
|
13
23
|
@spec_parser = SpecParser.new
|
|
14
24
|
@file_factory = File
|
|
15
25
|
end
|
|
16
26
|
|
|
17
|
-
def
|
|
27
|
+
def create_behaviour_runner(args, err, out, warn_if_no_files)
|
|
18
28
|
options = parse(args, err, out, warn_if_no_files)
|
|
19
29
|
# Some exit points in parse (--generate-options, --drb) don't return the options,
|
|
20
30
|
# but hand over control. In that case we don't want to continue.
|
|
21
|
-
return nil unless options.is_a?(
|
|
31
|
+
return nil unless options.is_a?(Options)
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
options.formatters.each do |formatter|
|
|
34
|
+
formatter.colour = options.colour if formatter.respond_to?(:colour=)
|
|
35
|
+
formatter.dry_run = options.dry_run if formatter.respond_to?(:dry_run=)
|
|
36
|
+
end
|
|
37
|
+
options.reporter = Reporter.new(options.formatters, options.backtrace_tweaker)
|
|
25
38
|
|
|
26
39
|
# this doesn't really belong here.
|
|
27
40
|
# it should, but the way things are coupled, it doesn't
|
|
@@ -30,21 +43,24 @@ module Spec
|
|
|
30
43
|
end
|
|
31
44
|
|
|
32
45
|
unless options.generate
|
|
33
|
-
|
|
46
|
+
if options.runner_type
|
|
47
|
+
options.runner_type.new(options)
|
|
48
|
+
else
|
|
49
|
+
BehaviourRunner.new(options)
|
|
50
|
+
end
|
|
34
51
|
end
|
|
35
52
|
end
|
|
36
53
|
|
|
37
54
|
def parse(args, err, out, warn_if_no_files)
|
|
38
55
|
options_file = nil
|
|
39
56
|
args_copy = args.dup
|
|
40
|
-
options =
|
|
41
|
-
options.
|
|
42
|
-
options.formatter_type = Formatter::ProgressBarFormatter
|
|
57
|
+
options = Options.new
|
|
58
|
+
options.formatters = []
|
|
43
59
|
options.backtrace_tweaker = QuietBacktraceTweaker.new
|
|
44
|
-
options.
|
|
60
|
+
options.examples = []
|
|
45
61
|
|
|
46
62
|
opts = ::OptionParser.new do |opts|
|
|
47
|
-
opts.banner = "Usage: spec
|
|
63
|
+
opts.banner = "Usage: spec (FILE|DIRECTORY|GLOB)+ [options]"
|
|
48
64
|
opts.separator ""
|
|
49
65
|
|
|
50
66
|
opts.on("-D", "--diff [FORMAT]", "Show diff of objects that are expected to be equal when they are not",
|
|
@@ -82,38 +98,74 @@ module Spec
|
|
|
82
98
|
options.colour = true
|
|
83
99
|
end
|
|
84
100
|
|
|
85
|
-
opts.on("-
|
|
86
|
-
|
|
101
|
+
opts.on("-e", "--example [NAME|FILE_NAME]", "Execute example(s) with matching name(s). If the argument is",
|
|
102
|
+
"the path to an existing file (typically generated by a previous",
|
|
103
|
+
"run using --format failing_examples:file.txt), then the examples",
|
|
104
|
+
"on each line of that file will be executed. If the file is empty,",
|
|
105
|
+
"all examples will be run (as if --example was not specified).",
|
|
106
|
+
" ",
|
|
107
|
+
"If the argument is not an existing file, then it is treated as",
|
|
108
|
+
"an example name directly, causing RSpec to run just the example",
|
|
109
|
+
"matching that name") do |example|
|
|
110
|
+
if(File.file?(example))
|
|
111
|
+
options.examples = File.open(example).read.split("\n")
|
|
112
|
+
else
|
|
113
|
+
options.examples = [example]
|
|
114
|
+
end
|
|
87
115
|
end
|
|
88
|
-
|
|
89
|
-
opts.on("-
|
|
116
|
+
|
|
117
|
+
opts.on("-s", "--spec [NAME]", "DEPRECATED - use -e instead", "(This will be removed when autotest works with -e)") do |example|
|
|
118
|
+
if(File.file?(example))
|
|
119
|
+
options.examples = File.open(example).read.split("\n")
|
|
120
|
+
else
|
|
121
|
+
options.examples = [example]
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
opts.on("-l", "--line LINE_NUMBER", Integer, "Execute behaviour or example at given line.",
|
|
126
|
+
"(does not work for dynamically generated specs)") do |line_number|
|
|
90
127
|
options.line_number = line_number.to_i
|
|
91
128
|
end
|
|
92
129
|
|
|
93
|
-
opts.on("-f", "--format FORMAT",
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
130
|
+
opts.on("-f", "--format FORMAT[:WHERE]", "Specifies what format to use for output. Specify WHERE to tell",
|
|
131
|
+
"the formatter where to write the output. All built-in formats",
|
|
132
|
+
"expect WHERE to be a file name, and will write to STDOUT if it's",
|
|
133
|
+
"not specified. The --format option may be specified several times",
|
|
134
|
+
"if you want several outputs",
|
|
135
|
+
" ",
|
|
136
|
+
"Builtin formats: ",
|
|
137
|
+
"progress|p : Text progress",
|
|
138
|
+
"specdoc|s : Behaviour doc as text",
|
|
139
|
+
"rdoc|r : Behaviour doc as RDoc",
|
|
140
|
+
"html|h : A nice HTML report",
|
|
141
|
+
"failing_examples|e : Write all failing examples - input for --example",
|
|
142
|
+
"failing_behaviours|b : Write all failing behaviours - input for --example",
|
|
143
|
+
" ",
|
|
144
|
+
"FORMAT can also be the name of a custom formatter class",
|
|
145
|
+
"(in which case you should also specify --require to load it)") do |format|
|
|
146
|
+
|
|
147
|
+
where = out
|
|
148
|
+
# This funky regexp checks whether we have a FILE_NAME or not
|
|
149
|
+
if (format =~ /([a-zA-Z_]+(?:::[a-zA-Z_]+)*):?(.*)/) && ($2 != '')
|
|
150
|
+
format = $1
|
|
151
|
+
where = $2
|
|
104
152
|
else
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
153
|
+
raise "When using several --format options only one of them can be without a file" if @out_used
|
|
154
|
+
@out_used = true
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
begin
|
|
158
|
+
formatter_type = BUILT_IN_FORMATTERS[format] || eval(format)
|
|
159
|
+
options.formatters << formatter_type.new(where)
|
|
160
|
+
rescue NameError
|
|
161
|
+
err.puts "Couldn't find formatter class #{format}"
|
|
162
|
+
err.puts "Make sure the --require option is specified *before* --format"
|
|
163
|
+
exit if out == $stdout
|
|
112
164
|
end
|
|
113
165
|
end
|
|
114
166
|
|
|
115
167
|
opts.on("-r", "--require FILE", "Require FILE before running specs",
|
|
116
|
-
"Useful for loading custom formatters or other extensions",
|
|
168
|
+
"Useful for loading custom formatters or other extensions.",
|
|
117
169
|
"If this option is used it must come before the others") do |req|
|
|
118
170
|
req.split(",").each{|file| require file}
|
|
119
171
|
end
|
|
@@ -121,31 +173,45 @@ module Spec
|
|
|
121
173
|
opts.on("-b", "--backtrace", "Output full backtrace") do
|
|
122
174
|
options.backtrace_tweaker = NoisyBacktraceTweaker.new
|
|
123
175
|
end
|
|
176
|
+
|
|
177
|
+
opts.on("-L", "--loadby STRATEGY", "Specify the strategy by which spec files should be loaded.",
|
|
178
|
+
"STRATEGY can currently only be 'mtime' (File modification time)",
|
|
179
|
+
"By default, spec files are loaded in alphabetical order if --loadby",
|
|
180
|
+
"is not specified.") do |loadby|
|
|
181
|
+
options.loadby = loadby
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
opts.on("-R", "--reverse", "Run examples in reverse order") do
|
|
185
|
+
options.reverse = true
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
opts.on("-t", "--timeout FLOAT", "Interrupt and fail each example that doesn't complete in the",
|
|
189
|
+
"specified time") do |timeout|
|
|
190
|
+
options.timeout = timeout.to_f
|
|
191
|
+
end
|
|
124
192
|
|
|
125
|
-
opts.on("-H", "--heckle CODE", "If all
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
193
|
+
opts.on("-H", "--heckle CODE", "If all examples pass, this will mutate the classes and methods",
|
|
194
|
+
"identified by CODE little by little and run all the examples again",
|
|
195
|
+
"for each mutation. The intent is that for each mutation, at least",
|
|
196
|
+
"one example *should* fail, and RSpec will tell you if this is not the",
|
|
197
|
+
"case. CODE should be either Some::Module, Some::Class or",
|
|
198
|
+
"Some::Fabulous#method") do |heckle|
|
|
129
199
|
heckle_runner = PLATFORM == 'i386-mswin32' ? 'spec/runner/heckle_runner_win' : 'spec/runner/heckle_runner'
|
|
130
200
|
require heckle_runner
|
|
131
201
|
options.heckle_runner = HeckleRunner.new(heckle)
|
|
132
202
|
end
|
|
133
203
|
|
|
134
|
-
opts.on("-d", "--dry-run", "
|
|
204
|
+
opts.on("-d", "--dry-run", "Invokes formatters without executing the examples.") do
|
|
135
205
|
options.dry_run = true
|
|
136
206
|
end
|
|
137
207
|
|
|
138
|
-
opts.on("-o", "--out OUTPUT_FILE", "Path to output file (defaults to STDOUT)") do |out_file|
|
|
139
|
-
options.out = File.new(out_file, 'w')
|
|
140
|
-
end
|
|
141
|
-
|
|
142
208
|
opts.on("-O", "--options PATH", "Read options from a file") do |options_file|
|
|
143
209
|
# Remove the --options option and the argument before writing to file
|
|
144
210
|
index = args_copy.index("-O") || args_copy.index("--options")
|
|
145
211
|
args_copy.delete_at(index)
|
|
146
212
|
args_copy.delete_at(index)
|
|
147
213
|
|
|
148
|
-
new_args = args_copy + IO.readlines(options_file).
|
|
214
|
+
new_args = args_copy + IO.readlines(options_file).map {|l| l.chomp.split " "}.flatten
|
|
149
215
|
return CommandLine.run(new_args, err, out, true, warn_if_no_files)
|
|
150
216
|
end
|
|
151
217
|
|
|
@@ -162,12 +228,22 @@ module Spec
|
|
|
162
228
|
out.puts "spec --options #{options_file}"
|
|
163
229
|
options.generate = true
|
|
164
230
|
end
|
|
231
|
+
|
|
232
|
+
opts.on("-U", "--runner RUNNER", "Use a custom BehaviourRunner.") do |runner|
|
|
233
|
+
begin
|
|
234
|
+
options.runner_type = eval(runner)
|
|
235
|
+
rescue NameError
|
|
236
|
+
err.puts "Couldn't find behaviour runner class #{runner}"
|
|
237
|
+
err.puts "Make sure the --require option is specified."
|
|
238
|
+
exit if out == $stdout
|
|
239
|
+
end
|
|
240
|
+
end
|
|
165
241
|
|
|
166
|
-
opts.on("-X", "--drb", "Run
|
|
167
|
-
# Remove the --
|
|
242
|
+
opts.on("-X", "--drb", "Run examples via DRb. (For example against script/spec_server)") do |options_file|
|
|
243
|
+
# Remove the --drb option
|
|
168
244
|
index = args_copy.index("-X") || args_copy.index("--drb")
|
|
169
245
|
args_copy.delete_at(index)
|
|
170
|
-
|
|
246
|
+
|
|
171
247
|
return DrbCommandLine.run(args_copy, err, out, true, warn_if_no_files)
|
|
172
248
|
end
|
|
173
249
|
|
|
@@ -193,16 +269,21 @@ module Spec
|
|
|
193
269
|
if options.line_number
|
|
194
270
|
set_spec_from_line_number(options, args, err)
|
|
195
271
|
end
|
|
272
|
+
|
|
273
|
+
if options.formatters.empty?
|
|
274
|
+
options.formatters << Formatter::ProgressBarFormatter.new(out)
|
|
275
|
+
end
|
|
196
276
|
|
|
197
277
|
options
|
|
198
278
|
end
|
|
199
279
|
|
|
200
280
|
def set_spec_from_line_number(options, args, err)
|
|
201
|
-
|
|
281
|
+
if options.examples.empty?
|
|
202
282
|
if args.length == 1
|
|
203
283
|
if @file_factory.file?(args[0])
|
|
204
284
|
source = @file_factory.open(args[0])
|
|
205
|
-
|
|
285
|
+
example = @spec_parser.spec_name_for(source, options.line_number)
|
|
286
|
+
options.examples = [example]
|
|
206
287
|
elsif @file_factory.directory?(args[0])
|
|
207
288
|
err.puts "You must specify one file, not a directory when using the --line option"
|
|
208
289
|
exit(1) if err == $stderr
|
|
@@ -215,7 +296,7 @@ module Spec
|
|
|
215
296
|
exit(3) if err == $stderr
|
|
216
297
|
end
|
|
217
298
|
else
|
|
218
|
-
err.puts "You cannot use both --line and --
|
|
299
|
+
err.puts "You cannot use both --line and --example"
|
|
219
300
|
exit(4) if err == $stderr
|
|
220
301
|
end
|
|
221
302
|
end
|