rspec-core 2.0.0.beta.8 → 2.0.0.beta.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -8
- data/Rakefile +9 -9
- data/Upgrade.markdown +6 -6
- data/VERSION +1 -1
- data/cucumber.yml +2 -7
- data/example_specs/passing/subject_example.rb +45 -0
- data/example_specs/spec_helper.rb +1 -1
- data/features/command_line/line_number_appended_to_path.feature +11 -13
- data/features/command_line/line_number_option.feature +3 -3
- data/features/configuration/custom_options.feature +71 -0
- data/features/configuration/options_file.feature +13 -13
- data/features/example_groups/describe_aliases.feature +1 -1
- data/features/example_groups/nested_groups.feature +4 -5
- data/features/filtering/inclusion_filters.feature +74 -0
- data/features/formatters/custom_formatter.feature +1 -1
- data/features/hooks/around_hook.feature +1 -1
- data/features/hooks/before_and_after_hooks.feature +61 -33
- data/features/hooks/described_class.feature +1 -1
- data/features/hooks/halt.feature +2 -2
- data/features/mock_framework_integration/use_flexmock.feature +2 -2
- data/features/mock_framework_integration/use_mocha.feature +2 -2
- data/features/mock_framework_integration/use_rr.feature +2 -2
- data/features/mock_framework_integration/use_rspec.feature +2 -2
- data/features/pending/pending_examples.feature +5 -5
- data/features/subject/explicit_subject.feature +4 -4
- data/features/subject/implicit_subject.feature +2 -2
- data/features/support/env.rb +1 -1
- data/lib/autotest/rspec2.rb +1 -1
- data/lib/rspec/autorun.rb +1 -1
- data/lib/rspec/core.rb +16 -9
- data/lib/rspec/core/around_proxy.rb +1 -1
- data/lib/rspec/core/backward_compatibility.rb +29 -1
- data/lib/rspec/core/configuration.rb +24 -16
- data/lib/rspec/core/configuration_options.rb +2 -2
- data/lib/rspec/core/deprecation.rb +3 -3
- data/lib/rspec/core/errors.rb +1 -1
- data/lib/rspec/core/example.rb +10 -3
- data/lib/rspec/core/example_group.rb +83 -58
- data/lib/rspec/core/formatters.rb +1 -1
- data/lib/rspec/core/formatters/base_formatter.rb +4 -4
- data/lib/rspec/core/formatters/base_text_formatter.rb +3 -3
- data/lib/rspec/core/formatters/documentation_formatter.rb +6 -9
- data/lib/rspec/core/formatters/helpers.rb +5 -4
- data/lib/rspec/core/formatters/progress_formatter.rb +1 -1
- data/lib/rspec/core/hooks.rb +1 -1
- data/lib/rspec/core/kernel_extensions.rb +3 -23
- data/lib/rspec/core/let.rb +73 -5
- data/lib/rspec/core/load_path.rb +1 -1
- data/lib/rspec/core/metadata.rb +20 -8
- data/lib/rspec/core/mocking/with_absolutely_nothing.rb +1 -1
- data/lib/rspec/core/mocking/with_flexmock.rb +1 -1
- data/lib/rspec/core/mocking/with_mocha.rb +1 -1
- data/lib/rspec/core/mocking/with_rr.rb +2 -2
- data/lib/rspec/core/mocking/with_rspec.rb +3 -3
- data/lib/rspec/core/object_extensions.rb +15 -0
- data/lib/rspec/core/pending.rb +2 -2
- data/lib/rspec/core/rake_task.rb +2 -2
- data/lib/rspec/core/ruby_project.rb +1 -1
- data/lib/rspec/core/runner.rb +13 -8
- data/lib/rspec/core/shared_example_group.rb +16 -6
- data/lib/rspec/core/subject.rb +23 -7
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +45 -38
- data/rspec-core.gemspec +17 -11
- data/spec/autotest/failed_results_re_spec.rb +1 -1
- data/spec/rspec/core/configuration_options_spec.rb +17 -7
- data/spec/rspec/core/configuration_spec.rb +46 -18
- data/spec/rspec/core/deprecations_spec.rb +8 -0
- data/spec/rspec/core/example_group_spec.rb +194 -56
- data/spec/rspec/core/example_spec.rb +18 -6
- data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -2
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +18 -2
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +29 -4
- data/spec/rspec/core/formatters/helpers_spec.rb +18 -11
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +2 -2
- data/spec/rspec/core/kernel_extensions_spec.rb +5 -9
- data/spec/rspec/core/metadata_spec.rb +29 -8
- data/spec/rspec/core/pending_example_spec.rb +7 -7
- data/spec/rspec/core/ruby_project_spec.rb +1 -1
- data/spec/rspec/core/runner_spec.rb +9 -9
- data/spec/rspec/core/shared_example_group_spec.rb +3 -3
- data/spec/rspec/core/subject_spec.rb +1 -1
- data/spec/rspec/core/world_spec.rb +16 -35
- data/spec/rspec/core_spec.rb +9 -9
- data/spec/spec_helper.rb +11 -13
- data/spec/support/matchers.rb +2 -2
- data/specs.watchr +11 -11
- metadata +16 -10
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Core
|
3
3
|
module Formatters
|
4
4
|
|
@@ -18,11 +18,11 @@ module Rspec
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def pending_examples
|
21
|
-
@pending_examples ||= ::
|
21
|
+
@pending_examples ||= ::RSpec.world.find(examples, :execution_result => { :status => 'pending' })
|
22
22
|
end
|
23
23
|
|
24
24
|
def failed_examples
|
25
|
-
@failed_examples ||= ::
|
25
|
+
@failed_examples ||= ::RSpec.world.find(examples, :execution_result => { :status => 'failed' })
|
26
26
|
end
|
27
27
|
|
28
28
|
def report(count)
|
@@ -109,7 +109,7 @@ module Rspec
|
|
109
109
|
protected
|
110
110
|
|
111
111
|
def configuration
|
112
|
-
|
112
|
+
RSpec.configuration
|
113
113
|
end
|
114
114
|
|
115
115
|
def backtrace_line(line)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
|
3
3
|
module Core
|
4
4
|
|
@@ -11,14 +11,14 @@ module Rspec
|
|
11
11
|
failed_examples.each_with_index do |failed_example, index|
|
12
12
|
exception = failed_example.execution_result[:exception_encountered]
|
13
13
|
padding = ' '
|
14
|
-
if exception.is_a?(
|
14
|
+
if exception.is_a?(RSpec::Core::PendingExampleFixedError)
|
15
15
|
output.puts "#{index.next}) #{failed_example} FIXED"
|
16
16
|
output.puts "#{padding}Expected pending '#{failed_example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised."
|
17
17
|
else
|
18
18
|
output.puts "#{index.next}) #{failed_example}"
|
19
19
|
output.puts "#{padding}Failure/Error: #{read_failed_line(exception, failed_example).strip}"
|
20
20
|
exception.message.split("\n").each do |line|
|
21
|
-
output.puts "#{padding}#{colorise(line, exception)
|
21
|
+
output.puts "#{padding}#{colorise(line, exception)}"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
|
3
3
|
module Core
|
4
4
|
|
@@ -44,15 +44,12 @@ module Rspec
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def failure_output(example, exception)
|
47
|
-
|
48
|
-
|
49
|
-
message = if expectation_not_met
|
50
|
-
"#{current_indentation}#{example.description} (FAILED)"
|
51
|
-
else
|
52
|
-
"#{current_indentation}#{example.description} (ERROR)"
|
53
|
-
end
|
47
|
+
red("#{current_indentation}#{example.description} (FAILED - #{next_failure_index})")
|
48
|
+
end
|
54
49
|
|
55
|
-
|
50
|
+
def next_failure_index
|
51
|
+
@next_failure_index ||= 0
|
52
|
+
@next_failure_index += 1
|
56
53
|
end
|
57
54
|
|
58
55
|
def passed_output(example)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
|
3
3
|
module Core
|
4
4
|
|
@@ -8,14 +8,15 @@ module Rspec
|
|
8
8
|
SUB_SECOND_PRECISION = 5
|
9
9
|
DEFAULT_PRECISION = 2
|
10
10
|
|
11
|
-
def format_seconds(float
|
11
|
+
def format_seconds(float)
|
12
12
|
precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
|
13
13
|
formatted = sprintf("%.#{precision}f", float)
|
14
14
|
strip_trailing_zeroes(formatted)
|
15
15
|
end
|
16
16
|
|
17
17
|
def strip_trailing_zeroes(string)
|
18
|
-
string.sub(/[^1-9]+$/, '')
|
18
|
+
stripped = string.sub(/[^1-9]+$/, '')
|
19
|
+
stripped.empty? ? "0" : stripped
|
19
20
|
end
|
20
21
|
|
21
22
|
end
|
@@ -24,4 +25,4 @@ module Rspec
|
|
24
25
|
|
25
26
|
end
|
26
27
|
|
27
|
-
end
|
28
|
+
end
|
data/lib/rspec/core/hooks.rb
CHANGED
@@ -1,25 +1,5 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
unless respond_to?(:debugger)
|
6
|
-
# Start a debugging session if ruby-debug is loaded with the -u/--debugger option
|
7
|
-
def debugger(steps=1)
|
8
|
-
# If not then just comment and proceed
|
9
|
-
$stderr.puts "debugger statement ignored, use -d or --debug option on rspec to enable debugging"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def describe(*args, &example_group_block)
|
14
|
-
args << {} unless args.last.is_a?(Hash)
|
15
|
-
args.last.update :caller => caller(1)
|
16
|
-
Rspec::Core::ExampleGroup.describe(*args, &example_group_block)
|
17
|
-
end
|
18
|
-
|
19
|
-
alias :context :describe
|
20
|
-
|
21
|
-
end
|
1
|
+
module Kernel
|
2
|
+
def debugger(*args)
|
3
|
+
$stderr.puts "debugger statement ignored, use -d or --debug option on rspec to enable debugging"
|
22
4
|
end
|
23
5
|
end
|
24
|
-
|
25
|
-
include Rspec::Core::KernelExtensions
|
data/lib/rspec/core/let.rb
CHANGED
@@ -1,15 +1,84 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Core
|
3
|
-
|
4
3
|
module Let
|
5
4
|
|
6
5
|
module ClassMethods
|
6
|
+
# Generates a method whose return value is memoized
|
7
|
+
# after the first call.
|
8
|
+
#
|
9
|
+
# == Examples
|
10
|
+
#
|
11
|
+
# describe Thing do
|
12
|
+
# let(:thing) { Thing.new }
|
13
|
+
#
|
14
|
+
# it "does something" do
|
15
|
+
# # first invocation, executes block, memoizes and returns result
|
16
|
+
# thing.do_something
|
17
|
+
#
|
18
|
+
# # second invocation, returns the memoized value
|
19
|
+
# thing.should be_something
|
20
|
+
# end
|
21
|
+
# end
|
7
22
|
def let(name, &block)
|
8
23
|
define_method(name) do
|
9
24
|
__memoized[name] ||= instance_eval(&block)
|
10
25
|
end
|
11
26
|
end
|
12
27
|
|
28
|
+
# Just like <tt>let()</tt>, except the block is invoked
|
29
|
+
# by an implicit <tt>before</tt> hook. This serves a dual
|
30
|
+
# purpose of setting up state and providing a memoized
|
31
|
+
# reference to that state.
|
32
|
+
#
|
33
|
+
# == Examples
|
34
|
+
#
|
35
|
+
# class Thing
|
36
|
+
# def self.count
|
37
|
+
# @count ||= 0
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# def self.count=(val)
|
41
|
+
# @count += val
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# def self.reset_count
|
45
|
+
# @count = 0
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# def initialize
|
49
|
+
# self.class.count += 1
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# describe Thing do
|
54
|
+
# after(:each) { Thing.reset_count }
|
55
|
+
#
|
56
|
+
# context "using let" do
|
57
|
+
# let(:thing) { Thing.new }
|
58
|
+
#
|
59
|
+
# it "is not invoked implicitly" do
|
60
|
+
# Thing.count.should == 0
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# it "can be invoked explicitly" do
|
64
|
+
# thing
|
65
|
+
# Thing.count.should == 1
|
66
|
+
# end
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# context "using let!" do
|
70
|
+
# let!(:thing) { Thing.new }
|
71
|
+
#
|
72
|
+
# it "is invoked implicitly" do
|
73
|
+
# Thing.count.should == 1
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# it "returns memoized version on first invocation" do
|
77
|
+
# thing
|
78
|
+
# Thing.count.should == 1
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
# end
|
13
82
|
def let!(name, &block)
|
14
83
|
let(name, &block)
|
15
84
|
before { __send__(name) }
|
@@ -17,17 +86,16 @@ module Rspec
|
|
17
86
|
end
|
18
87
|
|
19
88
|
module InstanceMethods
|
20
|
-
def __memoized
|
89
|
+
def __memoized # :nodoc:
|
21
90
|
@__memoized ||= {}
|
22
91
|
end
|
23
92
|
end
|
24
93
|
|
25
|
-
def self.included(mod)
|
94
|
+
def self.included(mod) # :nodoc:
|
26
95
|
mod.extend ClassMethods
|
27
96
|
mod.__send__ :include, InstanceMethods
|
28
97
|
end
|
29
98
|
|
30
99
|
end
|
31
|
-
|
32
100
|
end
|
33
101
|
end
|
data/lib/rspec/core/load_path.rb
CHANGED
data/lib/rspec/core/metadata.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Core
|
3
3
|
class Metadata < Hash
|
4
4
|
|
5
5
|
def initialize(superclass_metadata=nil)
|
6
6
|
@superclass_metadata = superclass_metadata
|
7
|
-
|
8
|
-
|
7
|
+
if @superclass_metadata
|
8
|
+
update(@superclass_metadata)
|
9
|
+
example_group = {:example_group => @superclass_metadata[:example_group]}
|
10
|
+
end
|
11
|
+
|
12
|
+
store(:example_group, example_group || {})
|
9
13
|
store(:behaviour, self[:example_group])
|
10
14
|
yield self if block_given?
|
11
15
|
end
|
@@ -45,12 +49,12 @@ module Rspec
|
|
45
49
|
#{"*"*50}
|
46
50
|
:#{key} is not allowed
|
47
51
|
|
48
|
-
|
52
|
+
RSpec reserves some hash keys for its own internal use,
|
49
53
|
including :#{key}, which is used on:
|
50
54
|
|
51
55
|
#{caller(0)[4]}.
|
52
56
|
|
53
|
-
Here are all of
|
57
|
+
Here are all of RSpec's reserved hash keys:
|
54
58
|
|
55
59
|
#{RESERVED_KEYS.join("\n ")}
|
56
60
|
#{"*"*50}
|
@@ -83,6 +87,15 @@ EOM
|
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
90
|
+
def relevant_line_numbers(metadata)
|
91
|
+
line_numbers = [metadata[:line_number]]
|
92
|
+
if metadata[:example_group]
|
93
|
+
line_numbers + relevant_line_numbers(metadata[:example_group])
|
94
|
+
else
|
95
|
+
line_numbers
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
86
99
|
def apply_condition(filter_on, filter, metadata=nil)
|
87
100
|
metadata ||= self
|
88
101
|
case filter
|
@@ -94,8 +107,7 @@ EOM
|
|
94
107
|
filter.call(metadata[filter_on]) rescue false
|
95
108
|
when Fixnum
|
96
109
|
if filter_on == :line_number
|
97
|
-
|
98
|
-
include?(world.preceding_example_or_group_line(filter))
|
110
|
+
relevant_line_numbers(metadata).include?(world.preceding_declaration_line(filter))
|
99
111
|
else
|
100
112
|
metadata[filter_on] == filter
|
101
113
|
end
|
@@ -107,7 +119,7 @@ EOM
|
|
107
119
|
private
|
108
120
|
|
109
121
|
def world
|
110
|
-
|
122
|
+
RSpec.world
|
111
123
|
end
|
112
124
|
|
113
125
|
def superclass_metadata
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'rr'
|
2
2
|
|
3
|
-
|
3
|
+
RSpec.configuration.backtrace_clean_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
|
4
4
|
|
5
|
-
module
|
5
|
+
module RSpec
|
6
6
|
module Core
|
7
7
|
module MockFrameworkAdapter
|
8
8
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'rspec/mocks/framework'
|
2
2
|
require 'rspec/mocks/extensions'
|
3
3
|
|
4
|
-
module
|
4
|
+
module RSpec
|
5
5
|
module Core
|
6
6
|
module MockFrameworkAdapter
|
7
7
|
|
8
|
-
include
|
8
|
+
include RSpec::Mocks::ExampleMethods
|
9
9
|
def _setup_mocks
|
10
|
-
$rspec_mocks ||=
|
10
|
+
$rspec_mocks ||= RSpec::Mocks::Space.new
|
11
11
|
end
|
12
12
|
def _verify_mocks
|
13
13
|
$rspec_mocks.verify_all
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
module ObjectExtensions
|
4
|
+
def describe(*args, &example_group_block)
|
5
|
+
args << {} unless args.last.is_a?(Hash)
|
6
|
+
args.last.update :caller => caller(1)
|
7
|
+
RSpec::Core::ExampleGroup.describe(*args, &example_group_block)
|
8
|
+
end
|
9
|
+
|
10
|
+
alias :context :describe
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
include RSpec::Core::ObjectExtensions
|
data/lib/rspec/core/pending.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Core
|
3
3
|
module Pending
|
4
4
|
def pending(message = 'No reason given')
|
@@ -10,7 +10,7 @@ module Rspec
|
|
10
10
|
running_example.metadata[:pending] = false
|
11
11
|
rescue Exception => e
|
12
12
|
end
|
13
|
-
raise
|
13
|
+
raise RSpec::Core::PendingExampleFixedError.new if result
|
14
14
|
end
|
15
15
|
throw :pending_declared_in_example, message
|
16
16
|
end
|
data/lib/rspec/core/rake_task.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'rake'
|
4
4
|
require 'rake/tasklib'
|
5
5
|
|
6
|
-
module
|
6
|
+
module RSpec
|
7
7
|
module Core
|
8
8
|
|
9
9
|
class RakeTask < ::Rake::TaskLib
|
@@ -51,7 +51,7 @@ module Rspec
|
|
51
51
|
|
52
52
|
def define # :nodoc:
|
53
53
|
actual_name = Hash === name ? name.keys.first : name
|
54
|
-
desc("Run
|
54
|
+
desc("Run RSpec code examples") unless ::Rake.application.last_comment
|
55
55
|
|
56
56
|
task name do
|
57
57
|
RakeFileUtils.send(:verbose, verbose) do
|