rspec 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,26 @@
|
|
1
|
+
module Spec
|
2
|
+
module Runner
|
3
|
+
class Options
|
4
|
+
attr_accessor(
|
5
|
+
:backtrace_tweaker,
|
6
|
+
:colour,
|
7
|
+
:context_lines,
|
8
|
+
:diff_format,
|
9
|
+
:differ_class,
|
10
|
+
:dry_run,
|
11
|
+
:examples,
|
12
|
+
:failure_file,
|
13
|
+
:formatters,
|
14
|
+
:generate,
|
15
|
+
:heckle_runner,
|
16
|
+
:line_number,
|
17
|
+
:loadby,
|
18
|
+
:reporter,
|
19
|
+
:reverse,
|
20
|
+
:runner_type,
|
21
|
+
:timeout,
|
22
|
+
:verbose
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/spec/runner/reporter.rb
CHANGED
@@ -2,36 +2,38 @@ module Spec
|
|
2
2
|
module Runner
|
3
3
|
class Reporter
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(formatters, backtrace_tweaker)
|
6
|
+
@formatters = formatters
|
7
7
|
@backtrace_tweaker = backtrace_tweaker
|
8
8
|
clear!
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
@
|
14
|
-
|
11
|
+
def add_behaviour(name)
|
12
|
+
@formatters.each{|f| f.add_behaviour(name)}
|
13
|
+
@behaviour_names << name
|
14
|
+
STDOUT.flush
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
@
|
19
|
-
|
17
|
+
def example_started(name)
|
18
|
+
@formatters.each{|f| f.example_started(name)}
|
19
|
+
STDOUT.flush
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def example_finished(name, error=nil, failure_location=nil)
|
23
|
+
@example_names << name
|
23
24
|
if error.nil?
|
24
|
-
|
25
|
+
example_passed(name)
|
25
26
|
else
|
26
|
-
|
27
|
-
spec_failed(name, Failure.new(@context_names.last, name, error))
|
27
|
+
example_failed(name, error, failure_location)
|
28
28
|
end
|
29
|
+
STDOUT.flush
|
29
30
|
end
|
30
31
|
|
31
|
-
def start(
|
32
|
+
def start(number_of_examples)
|
32
33
|
clear!
|
33
34
|
@start_time = Time.new
|
34
|
-
@
|
35
|
+
@formatters.each{|f| f.start(number_of_examples)}
|
36
|
+
STDOUT.flush
|
35
37
|
end
|
36
38
|
|
37
39
|
def end
|
@@ -40,18 +42,19 @@ module Spec
|
|
40
42
|
|
41
43
|
# Dumps the summary and returns the total number of failures
|
42
44
|
def dump
|
43
|
-
@
|
45
|
+
@formatters.each{|f| f.start_dump}
|
44
46
|
dump_failures
|
45
|
-
@
|
47
|
+
@formatters.each{|f| f.dump_summary(duration, @example_names.length, @failures.length)}
|
48
|
+
STDOUT.flush
|
46
49
|
@failures.length
|
47
50
|
end
|
48
51
|
|
49
|
-
|
52
|
+
private
|
50
53
|
|
51
54
|
def clear!
|
52
|
-
@
|
55
|
+
@behaviour_names = []
|
53
56
|
@failures = []
|
54
|
-
@
|
57
|
+
@example_names = []
|
55
58
|
@start_time = nil
|
56
59
|
@end_time = nil
|
57
60
|
end
|
@@ -59,7 +62,7 @@ module Spec
|
|
59
62
|
def dump_failures
|
60
63
|
return if @failures.empty?
|
61
64
|
@failures.inject(1) do |index, failure|
|
62
|
-
@
|
65
|
+
@formatters.each{|f| f.dump_failure(index, failure)}
|
63
66
|
index + 1
|
64
67
|
end
|
65
68
|
end
|
@@ -69,29 +72,33 @@ module Spec
|
|
69
72
|
return "0.0"
|
70
73
|
end
|
71
74
|
|
72
|
-
def
|
73
|
-
@
|
75
|
+
def example_passed(name)
|
76
|
+
@formatters.each{|f| f.example_passed(name)}
|
74
77
|
end
|
75
78
|
|
76
|
-
def
|
79
|
+
def example_failed(name, error, failure_location)
|
80
|
+
@backtrace_tweaker.tweak_backtrace(error, failure_location)
|
81
|
+
example_name = "#{@behaviour_names.last} #{name}"
|
82
|
+
@failure_io.puts(example_name) unless @failure_io.nil?
|
83
|
+
failure = Failure.new(example_name, error)
|
77
84
|
@failures << failure
|
78
|
-
@
|
85
|
+
@formatters.each{|f| f.example_failed(name, @failures.length, failure)}
|
86
|
+
STDOUT.flush
|
79
87
|
end
|
80
|
-
|
88
|
+
|
81
89
|
class Failure
|
82
90
|
attr_reader :exception
|
83
91
|
|
84
|
-
def initialize(
|
85
|
-
@
|
86
|
-
@spec_name = spec_name
|
92
|
+
def initialize(example_name, exception)
|
93
|
+
@example_name = example_name
|
87
94
|
@exception = exception
|
88
95
|
end
|
89
96
|
|
90
97
|
def header
|
91
98
|
if expectation_not_met?
|
92
|
-
"'#{@
|
99
|
+
"'#{@example_name}' FAILED"
|
93
100
|
else
|
94
|
-
"#{@exception.class.name} in '#{@
|
101
|
+
"#{@exception.class.name} in '#{@example_name}'"
|
95
102
|
end
|
96
103
|
end
|
97
104
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Spec
|
2
2
|
module Runner
|
3
|
-
# Parses a spec file and finds the nearest
|
3
|
+
# Parses a spec file and finds the nearest example for a given line number.
|
4
4
|
class SpecParser
|
5
5
|
def spec_name_for(io, line_number)
|
6
6
|
source = io.read
|
7
|
-
|
8
|
-
|
9
|
-
if
|
10
|
-
"#{
|
11
|
-
elsif
|
12
|
-
|
7
|
+
behaviour, behaviour_line = behaviour_at_line(source, line_number)
|
8
|
+
example, example_line = example_at_line(source, line_number)
|
9
|
+
if behaviour && example && (behaviour_line < example_line)
|
10
|
+
"#{behaviour} #{example}"
|
11
|
+
elsif behaviour
|
12
|
+
behaviour
|
13
13
|
else
|
14
14
|
nil
|
15
15
|
end
|
@@ -17,17 +17,18 @@ module Spec
|
|
17
17
|
|
18
18
|
protected
|
19
19
|
|
20
|
-
def
|
21
|
-
find_above(source, line_number, /^\s*context\s+
|
20
|
+
def behaviour_at_line(source, line_number)
|
21
|
+
find_above(source, line_number, /^\s*(context|describe)\s+(.*)\s+do/)
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
find_above(source, line_number, /^\s*specify\s+
|
24
|
+
def example_at_line(source, line_number)
|
25
|
+
find_above(source, line_number, /^\s*(specify|it)\s+(.*)\s+do/)
|
26
26
|
end
|
27
27
|
|
28
|
+
# Returns the context/describe or specify/it name and the line number
|
28
29
|
def find_above(source, line_number, pattern)
|
29
|
-
lines_above_reversed(source, line_number).
|
30
|
-
return $
|
30
|
+
lines_above_reversed(source, line_number).each_with_index do |line, n|
|
31
|
+
return [parse_description($2), line_number-n] if line =~ pattern
|
31
32
|
end
|
32
33
|
nil
|
33
34
|
end
|
@@ -36,6 +37,14 @@ module Spec
|
|
36
37
|
lines = source.split("\n")
|
37
38
|
lines[0...line_number].reverse
|
38
39
|
end
|
40
|
+
|
41
|
+
def parse_description(str)
|
42
|
+
return str[1..-2] if str =~ /^['"].*['"]$/
|
43
|
+
if matches = /^(.*)\s*,\s*['"](.*)['"]$/.match(str)
|
44
|
+
return "#{matches[1]}#{matches[2]}"
|
45
|
+
end
|
46
|
+
return str
|
47
|
+
end
|
39
48
|
end
|
40
49
|
end
|
41
50
|
end
|
data/lib/spec/translator.rb
CHANGED
@@ -1,87 +1,104 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
class Translator
|
5
|
-
def
|
6
|
-
from = File.expand_path(from)
|
7
|
-
to = File.expand_path(to)
|
8
|
-
if File.directory?(from)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
post
|
50
|
-
post
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
/^
|
69
|
-
/^
|
70
|
-
|
71
|
-
|
72
|
-
/^
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
class Translator
|
5
|
+
def translate(from, to)
|
6
|
+
from = File.expand_path(from)
|
7
|
+
to = File.expand_path(to)
|
8
|
+
if File.directory?(from)
|
9
|
+
translate_dir(from, to)
|
10
|
+
elsif(from =~ /\.rb$/)
|
11
|
+
translate_file(from, to)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def translate_dir(from, to)
|
16
|
+
FileUtils.mkdir_p(to) unless File.directory?(to)
|
17
|
+
Dir["#{from}/*"].each do |sub_from|
|
18
|
+
path = sub_from[from.length+1..-1]
|
19
|
+
sub_to = File.join(to, path)
|
20
|
+
translate(sub_from, sub_to)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def translate_file(from, to)
|
25
|
+
translation = ""
|
26
|
+
File.open(from) do |io|
|
27
|
+
io.each_line do |line|
|
28
|
+
translation << translate_line(line)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
File.open(to, "w") do |io|
|
32
|
+
io.write(translation)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def translate_line(line)
|
37
|
+
return line if line =~ /(should_not|should)_receive/
|
38
|
+
|
39
|
+
line.gsub!(/(^\s*)context([\s*|\(]['|"|A-Z])/, '\1describe\2')
|
40
|
+
line.gsub!(/(^\s*)specify([\s*|\(]['|"|A-Z])/, '\1it\2')
|
41
|
+
line.gsub!(/(^\s*)context_setup(\s*[do|\{])/, '\1before(:all)\2')
|
42
|
+
line.gsub!(/(^\s*)context_teardown(\s*[do|\{])/, '\1after(:all)\2')
|
43
|
+
line.gsub!(/(^\s*)setup(\s*[do|\{])/, '\1before(:each)\2')
|
44
|
+
line.gsub!(/(^\s*)teardown(\s*[do|\{])/, '\1after(:each)\2')
|
45
|
+
|
46
|
+
if line =~ /(.*\.)(should_not|should)(?:_be)(?!_)(.*)/m
|
47
|
+
pre = $1
|
48
|
+
should = $2
|
49
|
+
post = $3
|
50
|
+
be_or_equal = post =~ /(<|>)/ ? "be" : "equal"
|
51
|
+
|
52
|
+
return "#{pre}#{should} #{be_or_equal}#{post}"
|
53
|
+
end
|
54
|
+
|
55
|
+
if line =~ /(.*\.)(should_not|should)_(?!not)\s*(.*)/m
|
56
|
+
pre = $1
|
57
|
+
should = $2
|
58
|
+
post = $3
|
59
|
+
|
60
|
+
post.gsub!(/^raise/, 'raise_error')
|
61
|
+
post.gsub!(/^throw/, 'throw_symbol')
|
62
|
+
|
63
|
+
unless standard_matcher?(post)
|
64
|
+
post = "be_#{post}"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Add parenthesis
|
68
|
+
post.gsub!(/^(\w+)\s+([\w|\.|\,|\(.*\)|\'|\"|\:|@| ]+)(\})/, '\1(\2)\3') # inside a block
|
69
|
+
post.gsub!(/^(\w+)\s+([\w|\.|\,|\(.*\)|\{.*\}|\'|\"|\:|@| ]+)/, '\1(\2)')
|
70
|
+
post.gsub!(/(\s+\))/, ')')
|
71
|
+
post.gsub!(/\)\}/, ') }')
|
72
|
+
post.gsub!(/^(\w+)\s+(\/.*\/)/, '\1(\2)') #regexps
|
73
|
+
line = "#{pre}#{should} #{post}"
|
74
|
+
end
|
75
|
+
|
76
|
+
line
|
77
|
+
end
|
78
|
+
|
79
|
+
def standard_matcher?(matcher)
|
80
|
+
patterns = [
|
81
|
+
/^be/,
|
82
|
+
/^be_close/,
|
83
|
+
/^eql/,
|
84
|
+
/^equal/,
|
85
|
+
/^has/,
|
86
|
+
/^have/,
|
87
|
+
/^change/,
|
88
|
+
/^include/,
|
89
|
+
/^match/,
|
90
|
+
/^raise_error/,
|
91
|
+
/^respond_to/,
|
92
|
+
/^satisfy/,
|
93
|
+
/^throw_symbol/,
|
94
|
+
# Extra ones that we use in spec_helper
|
95
|
+
/^pass/,
|
96
|
+
/^fail/,
|
97
|
+
/^fail_with/,
|
98
|
+
]
|
99
|
+
matched = patterns.detect{ |p| matcher =~ p }
|
100
|
+
!matched.nil?
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
87
104
|
end
|
data/lib/spec/version.rb
CHANGED
@@ -1,25 +1,17 @@
|
|
1
1
|
module Spec
|
2
2
|
module VERSION
|
3
|
-
def self.build_tag
|
4
|
-
tag = "REL_" + [MAJOR, MINOR, TINY].join('_')
|
5
|
-
if defined?(RELEASE_CANDIDATE)
|
6
|
-
tag << "_" << RELEASE_CANDIDATE
|
7
|
-
end
|
8
|
-
tag
|
9
|
-
end
|
10
|
-
|
11
3
|
unless defined? MAJOR
|
12
4
|
MAJOR = 0
|
13
|
-
MINOR =
|
14
|
-
TINY =
|
15
|
-
|
5
|
+
MINOR = 9
|
6
|
+
TINY = 0
|
7
|
+
RELEASE_CANDIDATE = nil # "beta-1"
|
16
8
|
|
17
|
-
# RANDOM_TOKEN: 0.
|
18
|
-
REV = "$LastChangedRevision:
|
9
|
+
# RANDOM_TOKEN: 0.909189653221202
|
10
|
+
REV = "$LastChangedRevision: 1874 $".match(/LastChangedRevision: (\d+)/)[1]
|
19
11
|
|
20
12
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
21
|
-
|
22
|
-
|
13
|
+
TAG = "REL_#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('_')}".upcase.gsub(/\.|-/, '_')
|
14
|
+
FULL_VERSION = "#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('.')} (r#{REV})"
|
23
15
|
|
24
16
|
NAME = "RSpec"
|
25
17
|
URL = "http://rspec.rubyforge.org/"
|