rspec 0.6.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +90 -1
- data/EXAMPLES.rd +28 -6
- data/MIT-LICENSE +20 -0
- data/README +18 -12
- data/Rakefile +60 -54
- data/examples/custom_formatter.rb +4 -4
- data/examples/helper_method_example.rb +11 -0
- data/examples/mocking_example.rb +19 -2
- data/examples/partial_mock_example.rb +28 -0
- data/examples/stack_spec.rb +8 -8
- data/examples/stubbing_example.rb +50 -9
- data/examples/test_case_spec.rb +6 -6
- data/lib/spec.rb +1 -2
- data/lib/spec/callback.rb +0 -0
- data/lib/spec/expectations.rb +3 -6
- data/lib/spec/expectations/diff.rb +23 -47
- data/lib/spec/expectations/differs/default.rb +62 -0
- data/lib/spec/expectations/{exceptions.rb → errors.rb} +0 -0
- data/lib/spec/expectations/extensions.rb +4 -0
- data/lib/spec/expectations/extensions/inspect_for_expectation_not_met_error.rb +14 -0
- data/lib/spec/expectations/extensions/numeric.rb +5 -0
- data/lib/spec/expectations/{expectations.rb → extensions/object.rb} +3 -6
- data/lib/spec/expectations/extensions/symbol.rb +5 -0
- data/lib/spec/expectations/should.rb +4 -0
- data/lib/spec/expectations/should/base.rb +42 -0
- data/lib/spec/expectations/should/have.rb +79 -0
- data/lib/spec/expectations/should/not.rb +72 -0
- data/lib/spec/expectations/should/should.rb +83 -0
- data/lib/spec/expectations/sugar.rb +6 -25
- data/lib/spec/mocks.rb +5 -1
- data/lib/spec/mocks/argument_expectation.rb +15 -1
- data/lib/spec/mocks/error_generator.rb +72 -0
- data/lib/spec/mocks/{exceptions.rb → errors.rb} +0 -0
- data/lib/spec/mocks/extensions/object.rb +3 -0
- data/lib/spec/mocks/message_expectation.rb +80 -73
- data/lib/spec/mocks/mock.rb +4 -69
- data/lib/spec/mocks/mock_handler.rb +158 -0
- data/lib/spec/mocks/mock_methods.rb +44 -0
- data/lib/spec/mocks/order_group.rb +10 -2
- data/lib/spec/rake/spectask.rb +20 -18
- data/lib/spec/rake/{rcov_verify.rb → verify_rcov.rb} +2 -2
- data/lib/spec/runner.rb +3 -1
- data/lib/spec/runner/backtrace_tweaker.rb +2 -1
- data/lib/spec/runner/context.rb +10 -16
- data/lib/spec/runner/context_eval.rb +40 -40
- data/lib/spec/runner/execution_context.rb +1 -12
- data/lib/spec/runner/{kernel_ext.rb → extensions/kernel.rb} +2 -2
- data/lib/spec/runner/{instance_exec.rb → extensions/object.rb} +0 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +25 -18
- data/lib/spec/runner/formatter/html_formatter.rb +81 -101
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +9 -9
- data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
- data/lib/spec/runner/formatter/specdoc_formatter.rb +7 -6
- data/lib/spec/runner/option_parser.rb +41 -5
- data/lib/spec/runner/reporter.rb +3 -15
- data/lib/spec/runner/spec_should_raise_handler.rb +74 -0
- data/lib/spec/runner/specification.rb +33 -14
- data/lib/spec/version.rb +6 -3
- data/vendor/watir/README.txt +1 -1
- metadata +34 -68
- data/bin/test2spec +0 -112
- data/examples/helper_method_spec.rb +0 -12
- data/lib/spec/expectations/have_helper.rb +0 -41
- data/lib/spec/expectations/helper.rb +0 -4
- data/lib/spec/expectations/should_base.rb +0 -52
- data/lib/spec/expectations/should_helper.rb +0 -93
- data/lib/spec/expectations/should_negator.rb +0 -71
- data/lib/spec/test_to_spec/ruby2ruby.rb +0 -492
- data/lib/spec/test_to_spec/sexp_transformer.rb +0 -196
- data/lib/spec/test_to_spec/test_case_ext.rb +0 -22
- data/lib/spec/test_to_spec/translation_test_runner.rb +0 -147
- data/test/spec/expectations/arbitrary_operator_test.rb +0 -55
- data/test/spec/expectations/arbitrary_predicate_test.rb +0 -163
- data/test/spec/expectations/containment_test.rb +0 -129
- data/test/spec/expectations/diff_test.rb +0 -62
- data/test/spec/expectations/identity_test.rb +0 -75
- data/test/spec/expectations/object_equality_test.rb +0 -65
- data/test/spec/expectations/raising_test.rb +0 -106
- data/test/spec/expectations/regex_matching_test.rb +0 -36
- data/test/spec/expectations/should_have_test.rb +0 -169
- data/test/spec/expectations/should_satisfy_test.rb +0 -37
- data/test/spec/expectations/sugar_test.rb +0 -93
- data/test/spec/expectations/supported_symbols_test.rb +0 -33
- data/test/spec/expectations/throwing_test.rb +0 -55
- data/test/spec/expectations/true_false_special_case_test.rb +0 -85
- data/test/spec/expectations/typing_test.rb +0 -108
- data/test/spec/mocks/mock_arg_constraints_test.rb +0 -113
- data/test/spec/mocks/mock_counts_test.rb +0 -431
- data/test/spec/mocks/mock_ordering_test.rb +0 -109
- data/test/spec/mocks/mock_test.rb +0 -220
- data/test/spec/mocks/null_object_test.rb +0 -37
- data/test/spec/runner/backtrace_tweaker_test.rb +0 -90
- data/test/spec/runner/context_matching_test.rb +0 -35
- data/test/spec/runner/context_runner_test.rb +0 -62
- data/test/spec/runner/context_test.rb +0 -191
- data/test/spec/runner/execution_context_test.rb +0 -45
- data/test/spec/runner/formatter/failure_dump_test.rb +0 -94
- data/test/spec/runner/formatter/html_formatter_test.rb +0 -48
- data/test/spec/runner/formatter/progress_bar_formatter_test.rb +0 -56
- data/test/spec/runner/formatter/rdoc_formatter_test.rb +0 -51
- data/test/spec/runner/formatter/specdoc_formatter_test.rb +0 -57
- data/test/spec/runner/kernel_ext_test.rb +0 -13
- data/test/spec/runner/option_parser_test.rb +0 -141
- data/test/spec/runner/reporter_test.rb +0 -128
- data/test/spec/runner/spec_matcher_test.rb +0 -47
- data/test/spec/runner/specification_test.rb +0 -121
- data/test/spec/test_to_spec/ruby_to_ruby_test.rb +0 -79
- data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +0 -207
- data/test/spec/test_to_spec/sexp_transformer_test.rb +0 -303
- data/test/spec/test_to_spec/test_case_ext_test.rb +0 -25
- data/test/spec/test_to_spec/testfiles/test_unit_api_spec.rb +0 -75
- data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +0 -70
- data/test/test_classes.rb +0 -102
- data/test/test_helper.rb +0 -32
data/lib/spec/mocks/mock.rb
CHANGED
@@ -1,80 +1,15 @@
|
|
1
1
|
module Spec
|
2
2
|
module Mocks
|
3
|
-
|
3
|
+
class Mock
|
4
|
+
include MockMethods
|
5
|
+
|
4
6
|
# Creates a new mock with a +name+ (that will be used in error messages only)
|
5
7
|
# Options:
|
6
8
|
# * <tt>:null_object</tt> - if true, the mock object acts as a forgiving null object allowing any message to be sent to it.
|
7
9
|
def initialize(name, options={})
|
8
10
|
@name = name
|
9
|
-
@options =
|
10
|
-
@expectations = []
|
11
|
-
@expectation_ordering = OrderGroup.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def should_receive(sym, &block)
|
15
|
-
add MessageExpectation, caller(1)[0], sym, &block
|
16
|
-
end
|
17
|
-
|
18
|
-
def should_not_receive(sym, &block)
|
19
|
-
add NegativeMessageExpectation, caller(1)[0], sym, &block
|
20
|
-
end
|
21
|
-
|
22
|
-
def __verify #:nodoc:
|
23
|
-
@expectations.each do |expectation|
|
24
|
-
expectation.verify_messages_received
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def method_missing(sym, *args, &block)
|
29
|
-
begin
|
30
|
-
return self if @options[:null_object]
|
31
|
-
super(sym, *args, &block)
|
32
|
-
rescue NoMethodError
|
33
|
-
arg_message = args.collect{|arg| "<#{arg}:#{arg.class.name}>"}.join(", ")
|
34
|
-
Kernel::raise Spec::Mocks::MockExpectationError, "Mock '#{@name}' received unexpected message '#{sym}' with [#{arg_message}]"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
DEFAULT_OPTIONS = {
|
41
|
-
:null_object => false
|
42
|
-
}
|
43
|
-
|
44
|
-
def add(expectation_class, expected_from, sym, &block)
|
45
|
-
define_expected_method(sym)
|
46
|
-
expectation = expectation_class.send(:new, @name, @expectation_ordering, expected_from, sym, block_given? ? block : nil)
|
47
|
-
@expectations << expectation
|
48
|
-
expectation
|
49
|
-
end
|
50
|
-
|
51
|
-
def metaclass
|
52
|
-
class << self; self; end
|
53
|
-
end
|
54
|
-
|
55
|
-
def define_expected_method(sym)
|
56
|
-
metaclass.__send__ :class_eval, %{
|
57
|
-
def #{sym}(*args, &block)
|
58
|
-
message_received :#{sym}, *args, &block # ?
|
59
|
-
end
|
60
|
-
}
|
11
|
+
@options = options
|
61
12
|
end
|
62
|
-
|
63
|
-
def message_received(sym, *args, &block)
|
64
|
-
if expectation = find_matching_expectation(sym, *args)
|
65
|
-
expectation.invoke(args, block)
|
66
|
-
else
|
67
|
-
method_missing(sym, *args, &block)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def find_matching_expectation(sym, *args)
|
72
|
-
expectation = @expectations.find {|expectation| expectation.matches(sym, args)}
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class Mock
|
77
|
-
include MockInstanceMethods
|
78
13
|
end
|
79
14
|
end
|
80
15
|
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
module Spec
|
2
|
+
module Mocks
|
3
|
+
class MockHandler
|
4
|
+
def initialize(target, name, options={})
|
5
|
+
@target = target
|
6
|
+
@name = name
|
7
|
+
@error_generator = ErrorGenerator.new target, name
|
8
|
+
@expectation_ordering = OrderGroup.new @error_generator
|
9
|
+
@expectations = []
|
10
|
+
@messages_received = []
|
11
|
+
@stubs = []
|
12
|
+
@proxied_methods = []
|
13
|
+
@options = options ? DEFAULT_OPTIONS.dup.merge(options) : DEFAULT_OPTIONS
|
14
|
+
end
|
15
|
+
|
16
|
+
DEFAULT_OPTIONS = {
|
17
|
+
:null_object => false,
|
18
|
+
:auto_verify => true
|
19
|
+
}
|
20
|
+
|
21
|
+
def null_object?
|
22
|
+
@options[:null_object]
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_message_expectation(expected_from, sym, opts={}, &block)
|
26
|
+
__add expected_from, sym, block
|
27
|
+
@expectations << MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil, 1, opts)
|
28
|
+
@expectations.last
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_negative_message_expectation(expected_from, sym, &block)
|
32
|
+
__add expected_from, sym, block
|
33
|
+
@expectations << NegativeMessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil)
|
34
|
+
@expectations.last
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_stub(expected_from, sym)
|
38
|
+
__add expected_from, sym, nil
|
39
|
+
@stubs << MethodStub.new(@error_generator, @expectation_ordering, expected_from, sym, nil)
|
40
|
+
@stubs.last
|
41
|
+
end
|
42
|
+
|
43
|
+
def __add expected_from, sym, block
|
44
|
+
Runner::Specification.add_listener(self) if @options[:auto_verify]
|
45
|
+
define_expected_method(sym)
|
46
|
+
end
|
47
|
+
|
48
|
+
def spec_finished spec
|
49
|
+
verify
|
50
|
+
end
|
51
|
+
|
52
|
+
def define_expected_method(sym)
|
53
|
+
if @target.respond_to? sym
|
54
|
+
metaclass_eval %-
|
55
|
+
alias_method :#{__pre_proxied_method_name(sym)}, :#{sym}
|
56
|
+
-
|
57
|
+
@proxied_methods << sym
|
58
|
+
end
|
59
|
+
|
60
|
+
metaclass_eval %-
|
61
|
+
def #{sym}(*args, &block)
|
62
|
+
__mock_handler.message_received :#{sym}, *args, &block
|
63
|
+
end
|
64
|
+
-
|
65
|
+
end
|
66
|
+
|
67
|
+
def __pre_proxied_method_name method_name
|
68
|
+
"original_#{method_name.to_s.delete('!').delete('[').delete('\]')}_before_proxy"
|
69
|
+
end
|
70
|
+
|
71
|
+
def verify #:nodoc:
|
72
|
+
begin
|
73
|
+
verify_expectations
|
74
|
+
ensure
|
75
|
+
reset
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def reset
|
80
|
+
clear_expectations
|
81
|
+
clear_stubs
|
82
|
+
reset_proxied_methods
|
83
|
+
clear_proxied_methods
|
84
|
+
end
|
85
|
+
|
86
|
+
def verify_expectations
|
87
|
+
@expectations.each do |expectation|
|
88
|
+
expectation.verify_messages_received
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def reset_proxied_methods
|
93
|
+
@proxied_methods.each do |method_name|
|
94
|
+
if @target.respond_to? __pre_proxied_method_name(method_name)
|
95
|
+
metaclass_eval %-
|
96
|
+
alias_method :#{method_name}, :#{__pre_proxied_method_name(method_name)}
|
97
|
+
remove_method :#{__pre_proxied_method_name(method_name)}
|
98
|
+
-
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def clear_expectations #:nodoc:
|
104
|
+
@expectations.clear
|
105
|
+
end
|
106
|
+
|
107
|
+
def clear_stubs #:nodoc:
|
108
|
+
@stubs.clear
|
109
|
+
end
|
110
|
+
|
111
|
+
def clear_proxied_methods #:nodoc:
|
112
|
+
@proxied_methods.clear
|
113
|
+
end
|
114
|
+
|
115
|
+
def metaclass_eval str
|
116
|
+
(class << @target; self; end).class_eval str
|
117
|
+
end
|
118
|
+
|
119
|
+
def received_message?(sym, *args, &block)
|
120
|
+
return true if @messages_received.find {|array| array == [sym, args, block]}
|
121
|
+
return false
|
122
|
+
end
|
123
|
+
|
124
|
+
def find_matching_expectation(sym, *args)
|
125
|
+
@expectations.find {|expectation| expectation.matches(sym, args)}
|
126
|
+
end
|
127
|
+
|
128
|
+
def find_almost_matching_expectation(sym, *args)
|
129
|
+
@expectations.find {|expectation| expectation.matches_name_but_not_args(sym, args)}
|
130
|
+
end
|
131
|
+
|
132
|
+
def find_matching_method_stub(sym)
|
133
|
+
@stubs.find {|stub| stub.matches(sym, [])}
|
134
|
+
end
|
135
|
+
|
136
|
+
def has_negative_expectation?(sym)
|
137
|
+
@expectations.detect {|expectation| expectation.negative_expectation_for?(sym)}
|
138
|
+
end
|
139
|
+
|
140
|
+
def message_received(sym, *args, &block)
|
141
|
+
if expectation = find_matching_expectation(sym, *args)
|
142
|
+
expectation.invoke(args, block)
|
143
|
+
elsif stub = find_matching_method_stub(sym)
|
144
|
+
stub.invoke([], nil)
|
145
|
+
elsif expectation = find_almost_matching_expectation(sym, *args)
|
146
|
+
raise_unexpected_message_error(sym, *args) unless has_negative_expectation?(sym) unless null_object?
|
147
|
+
else
|
148
|
+
@target.send :method_missing, sym, *args, &block
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def raise_unexpected_message_error sym, *args
|
153
|
+
@error_generator.raise_unexpected_message_error sym, *args
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Spec
|
2
|
+
module Mocks
|
3
|
+
module MockMethods
|
4
|
+
def should_receive(sym, opts={}, &block)
|
5
|
+
__mock_handler.add_message_expectation(opts[:expected_from] || caller(1)[0], sym, opts, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def should_not_receive(sym, &block)
|
9
|
+
__mock_handler.add_negative_message_expectation(caller(1)[0], sym, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub!(sym)
|
13
|
+
__mock_handler.add_stub caller(1)[0], sym
|
14
|
+
end
|
15
|
+
|
16
|
+
def received_message?(sym, *args, &block)
|
17
|
+
__mock_handler.received_message?(sym, *args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def __verify
|
21
|
+
__mock_handler.verify
|
22
|
+
end
|
23
|
+
|
24
|
+
def __reset_mock
|
25
|
+
__mock_handler.reset
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(sym, *args, &block)
|
29
|
+
__mock_handler.instance_eval {@messages_received << [sym, args, block]}
|
30
|
+
begin
|
31
|
+
return self if __mock_handler.null_object?
|
32
|
+
super(sym, *args, &block)
|
33
|
+
rescue NoMethodError
|
34
|
+
__mock_handler.raise_unexpected_message_error sym, *args
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def __mock_handler
|
40
|
+
@mock_handler ||= MockHandler.new(self, @name, @options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Spec
|
2
2
|
module Mocks
|
3
3
|
class OrderGroup
|
4
|
-
def initialize
|
4
|
+
def initialize error_generator
|
5
|
+
@error_generator = error_generator
|
5
6
|
@ordering = Array.new
|
6
7
|
end
|
7
8
|
|
@@ -13,9 +14,16 @@ module Spec
|
|
13
14
|
return @ordering.first == expectation
|
14
15
|
end
|
15
16
|
|
16
|
-
def consume
|
17
|
+
def consume
|
17
18
|
@ordering.shift
|
18
19
|
end
|
20
|
+
|
21
|
+
def handle_order_constraint expectation
|
22
|
+
return unless @ordering.include? expectation
|
23
|
+
return consume if ready_for?(expectation)
|
24
|
+
@error_generator.raise_out_of_order_error expectation.sym
|
25
|
+
end
|
26
|
+
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
data/lib/spec/rake/spectask.rb
CHANGED
@@ -93,7 +93,6 @@ module Spec
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def define
|
96
|
-
#raise "No spec files found." if file_list.empty?
|
97
96
|
spec_script = File.expand_path(File.dirname(__FILE__) + '/../../../bin/spec')
|
98
97
|
|
99
98
|
lib_path = @libs.join(File::PATH_SEPARATOR)
|
@@ -109,23 +108,26 @@ module Spec
|
|
109
108
|
ruby_opts.push( "-w" ) if @warning
|
110
109
|
|
111
110
|
redirect = @out.nil? ? "" : " > #{@out}"
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
ruby
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
111
|
+
|
112
|
+
unless file_list.empty?
|
113
|
+
# ruby [ruby_opts] -Ilib -S rcov [rcov_opts] bin/spec -- [spec_opts] examples
|
114
|
+
# or
|
115
|
+
# ruby [ruby_opts] -Ilib bin/spec [spec_opts] examples
|
116
|
+
begin
|
117
|
+
ruby(
|
118
|
+
ruby_opts.join(" ") + " " +
|
119
|
+
rcov_option_list +
|
120
|
+
(@rcov ? %[ -o "#{@rcov_dir}" ] : "") +
|
121
|
+
'"' + spec_script + '"' + " " +
|
122
|
+
(@rcov ? "-- " : "") +
|
123
|
+
file_list.collect { |fn| %["#{fn}"] }.join(' ') + " " +
|
124
|
+
spec_option_list + " " +
|
125
|
+
redirect
|
126
|
+
)
|
127
|
+
rescue => e
|
128
|
+
puts @failure_message if @failure_message
|
129
|
+
raise e if @fail_on_error
|
130
|
+
end
|
129
131
|
end
|
130
132
|
end
|
131
133
|
end
|
@@ -3,7 +3,7 @@ module RCov
|
|
3
3
|
# drop below a certain threshold. It should be run after
|
4
4
|
# running Spec::Rake::SpecTask.
|
5
5
|
class VerifyTask < Rake::TaskLib
|
6
|
-
# Name of the task. Defaults to :
|
6
|
+
# Name of the task. Defaults to :verify_rcov
|
7
7
|
attr_accessor :name
|
8
8
|
|
9
9
|
# Path to the index.html file generated by RCov, which
|
@@ -19,7 +19,7 @@ module RCov
|
|
19
19
|
# exception.
|
20
20
|
attr_accessor :threshold
|
21
21
|
|
22
|
-
def initialize(name=:
|
22
|
+
def initialize(name=:verify_rcov)
|
23
23
|
@name = name
|
24
24
|
@index_html = 'coverage/index.html'
|
25
25
|
@verbose = true
|
data/lib/spec/runner.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec/runner/formatter'
|
2
|
-
require 'spec/runner/instance_exec'
|
3
2
|
require 'spec/runner/context'
|
4
3
|
require 'spec/runner/context_eval'
|
5
4
|
require 'spec/runner/specification'
|
@@ -9,3 +8,6 @@ require 'spec/runner/option_parser'
|
|
9
8
|
require 'spec/runner/backtrace_tweaker'
|
10
9
|
require 'spec/runner/reporter'
|
11
10
|
require 'spec/runner/spec_matcher'
|
11
|
+
require 'spec/runner/extensions/kernel'
|
12
|
+
require 'spec/runner/extensions/object'
|
13
|
+
require 'spec/runner/spec_should_raise_handler'
|
@@ -7,7 +7,6 @@ module Spec
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
# Tweaks raised Exceptions to mask noisy (unneeded) parts of the backtrace
|
11
10
|
class NoisyBacktraceTweaker < BacktraceTweaker
|
12
11
|
def tweak_backtrace(error, spec_name)
|
13
12
|
return if error.backtrace.nil?
|
@@ -26,11 +25,13 @@ module Spec
|
|
26
25
|
line = tweak_instance_exec_line line, spec_name
|
27
26
|
line = nil if line =~ /\/lib\/ruby\//
|
28
27
|
line = nil if line =~ /\/lib\/spec\/expectations\//
|
28
|
+
line = nil if line =~ /\/lib\/spec\/method_proxy\//
|
29
29
|
line = nil if line =~ /\/lib\/spec\/mocks\//
|
30
30
|
line = nil if line =~ /\/lib\/spec\/rake\//
|
31
31
|
line = nil if line =~ /\/lib\/spec\/runner\//
|
32
32
|
line = nil if line =~ /\/lib\/spec\/stubs\//
|
33
33
|
line = nil if line =~ /bin\/spec:/
|
34
|
+
line = nil if line =~ /bin\/rcov:/
|
34
35
|
line = nil if line =~ /lib\/rspec_on_rails/
|
35
36
|
line = nil if line =~ /script\/rails_spec/
|
36
37
|
# TextMate's Ruby plugin
|
data/lib/spec/runner/context.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module Spec
|
2
2
|
module Runner
|
3
|
+
class ContextEvalModule < Module
|
4
|
+
end
|
3
5
|
class Context
|
4
6
|
module InstanceMethods
|
5
7
|
def initialize(name, &context_block)
|
6
8
|
@name = name
|
7
9
|
|
8
|
-
@context_eval_module =
|
10
|
+
@context_eval_module = ContextEvalModule.new
|
9
11
|
@context_eval_module.extend ContextEval::ModuleMethods
|
10
12
|
@context_eval_module.include ContextEval::InstanceMethods
|
11
13
|
before_context_eval
|
@@ -31,8 +33,8 @@ module Spec
|
|
31
33
|
@context_eval_module.teardown(&block)
|
32
34
|
end
|
33
35
|
|
34
|
-
def specify(spec_name, &block)
|
35
|
-
@context_eval_module.specify(spec_name, &block)
|
36
|
+
def specify(spec_name, opts={}, &block)
|
37
|
+
@context_eval_module.specify(spec_name, opts, &block)
|
36
38
|
end
|
37
39
|
|
38
40
|
def run(reporter, dry_run=false)
|
@@ -40,10 +42,13 @@ module Spec
|
|
40
42
|
|
41
43
|
prepare_execution_context_class
|
42
44
|
specifications.each do |specification|
|
43
|
-
|
44
|
-
specification.run(reporter, setup_block, teardown_block, dry_run, execution_context)
|
45
|
+
specification.run(reporter, setup_block, teardown_block, dry_run, execution_context(specification))
|
45
46
|
end
|
46
47
|
end
|
48
|
+
|
49
|
+
def execution_context specification
|
50
|
+
execution_context_class.new(specification)
|
51
|
+
end
|
47
52
|
|
48
53
|
def number_of_specs
|
49
54
|
specifications.length
|
@@ -89,14 +94,6 @@ module Spec
|
|
89
94
|
@context_eval_module.send :teardown_block
|
90
95
|
end
|
91
96
|
|
92
|
-
def setup_parts
|
93
|
-
@context_eval_module.send :setup_parts
|
94
|
-
end
|
95
|
-
|
96
|
-
def teardown_parts
|
97
|
-
@context_eval_module.send :teardown_parts
|
98
|
-
end
|
99
|
-
|
100
97
|
def prepare_execution_context_class
|
101
98
|
weave_in_context_modules
|
102
99
|
execution_context_class
|
@@ -121,9 +118,6 @@ module Spec
|
|
121
118
|
@context_eval_module.send :execution_context_class
|
122
119
|
end
|
123
120
|
|
124
|
-
def context_superclass
|
125
|
-
@context_eval_module.send :context_superclass
|
126
|
-
end
|
127
121
|
end
|
128
122
|
include InstanceMethods
|
129
123
|
end
|