rspec-core 2.0.0.beta.17 → 2.0.0.beta.18
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +5 -1
- data/Rakefile +4 -1
- data/Upgrade.markdown +28 -2
- data/VERSION +1 -1
- data/autotest/discover.rb +1 -1
- data/features/command_line/configure.feature +19 -0
- data/features/example_groups/shared_example_group.feature +125 -0
- data/features/hooks/around_hooks.feature +11 -2
- data/features/pending/pending_examples.feature +18 -6
- data/lib/autotest/rspec2.rb +1 -1
- data/lib/rspec/core.rb +1 -0
- data/lib/rspec/core/command_line_configuration.rb +62 -0
- data/lib/rspec/core/configuration.rb +39 -12
- data/lib/rspec/core/configuration_options.rb +5 -5
- data/lib/rspec/core/deprecation.rb +6 -6
- data/lib/rspec/core/errors.rb +1 -1
- data/lib/rspec/core/example.rb +25 -25
- data/lib/rspec/core/example_group.rb +30 -14
- data/lib/rspec/core/formatters/base_formatter.rb +25 -25
- data/lib/rspec/core/formatters/base_text_formatter.rb +11 -10
- data/lib/rspec/core/formatters/documentation_formatter.rb +2 -2
- data/lib/rspec/core/formatters/helpers.rb +6 -6
- data/lib/rspec/core/formatters/html_formatter.rb +13 -12
- data/lib/rspec/core/formatters/progress_formatter.rb +1 -1
- data/lib/rspec/core/formatters/snippet_extractor.rb +5 -5
- data/lib/rspec/core/hooks.rb +3 -3
- data/lib/rspec/core/kernel_extensions.rb +1 -1
- data/lib/rspec/core/let.rb +5 -5
- data/lib/rspec/core/metadata.rb +2 -2
- data/lib/rspec/core/mocking/with_absolutely_nothing.rb +3 -3
- data/lib/rspec/core/mocking/with_mocha.rb +5 -5
- data/lib/rspec/core/mocking/with_rr.rb +3 -3
- data/lib/rspec/core/mocking/with_rspec.rb +3 -3
- data/lib/rspec/core/option_parser.rb +8 -4
- data/lib/rspec/core/rake_task.rb +5 -0
- data/lib/rspec/core/ruby_project.rb +1 -1
- data/lib/rspec/core/shared_example_group.rb +2 -2
- data/lib/rspec/core/subject.rb +10 -4
- data/lib/rspec/core/world.rb +5 -5
- data/rspec-core.gemspec +19 -11
- data/spec/autotest/rspec_spec.rb +14 -14
- data/spec/rspec/core/command_line_configuration_spec.rb +26 -0
- data/spec/rspec/core/command_line_spec.rb +5 -5
- data/spec/rspec/core/configuration_options_spec.rb +20 -20
- data/spec/rspec/core/configuration_spec.rb +10 -10
- data/spec/rspec/core/core_spec.rb +8 -8
- data/spec/rspec/core/deprecations_spec.rb +2 -2
- data/spec/rspec/core/drb_command_line_spec.rb +10 -10
- data/spec/rspec/core/example_group_spec.rb +46 -10
- data/spec/rspec/core/example_spec.rb +46 -12
- data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -46
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +4 -3
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +1 -1
- data/spec/rspec/core/formatters/helpers_spec.rb +2 -2
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +1 -1
- data/spec/rspec/core/formatters/html_formatted-1.9.1.html +1 -1
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +1 -1
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +10 -9
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +13 -13
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +1 -1
- data/spec/rspec/core/let_spec.rb +1 -1
- data/spec/rspec/core/metadata_spec.rb +9 -9
- data/spec/rspec/core/option_parser_spec.rb +3 -3
- data/spec/rspec/core/pending_example_spec.rb +1 -1
- data/spec/rspec/core/resources/custom_example_group_runner.rb +1 -1
- data/spec/rspec/core/runner_spec.rb +4 -4
- data/spec/rspec/core/shared_example_group_spec.rb +66 -162
- data/spec/rspec/core/subject_spec.rb +4 -4
- data/spec/rspec/core/world_spec.rb +38 -38
- metadata +21 -13
@@ -7,22 +7,22 @@ module RSpec
|
|
7
7
|
module Helpers
|
8
8
|
SUB_SECOND_PRECISION = 5
|
9
9
|
DEFAULT_PRECISION = 2
|
10
|
-
|
10
|
+
|
11
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
18
|
stripped = string.sub(/[^1-9]+$/, '')
|
19
19
|
stripped.empty? ? "0" : stripped
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
end
|
@@ -13,24 +13,24 @@ module RSpec
|
|
13
13
|
|
14
14
|
def message(message)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def initialize(output)
|
18
18
|
super
|
19
19
|
@example_group_number = 0
|
20
20
|
@example_number = 0
|
21
21
|
@header_red = nil
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# The number of the currently running example_group
|
25
25
|
def example_group_number
|
26
26
|
@example_group_number
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
# The number of the currently running example (a global counter)
|
30
30
|
def example_number
|
31
31
|
@example_number
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def start(example_count)
|
35
35
|
super
|
36
36
|
@output.puts html_header
|
@@ -38,7 +38,7 @@ module RSpec
|
|
38
38
|
@output.flush
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def example_group_started(example_group)
|
42
42
|
super
|
43
43
|
@example_group_red = false
|
44
44
|
@example_group_number += 1
|
@@ -52,7 +52,7 @@ module RSpec
|
|
52
52
|
@output.flush
|
53
53
|
end
|
54
54
|
|
55
|
-
def start_dump
|
55
|
+
def start_dump
|
56
56
|
@output.puts " </dl>"
|
57
57
|
@output.puts "</div>"
|
58
58
|
@output.flush
|
@@ -108,7 +108,7 @@ module RSpec
|
|
108
108
|
@snippet_extractor ||= SnippetExtractor.new
|
109
109
|
" <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(exception)}</code></pre>"
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def move_progress
|
113
113
|
@output.puts " <script type=\"text/javascript\">moveProgressBar('#{percent_done}');</script>"
|
114
114
|
@output.flush
|
@@ -128,12 +128,13 @@ module RSpec
|
|
128
128
|
def dump_pending
|
129
129
|
end
|
130
130
|
|
131
|
-
def dump_summary
|
131
|
+
def dump_summary(duration, example_count, failure_count, pending_count)
|
132
|
+
# TODO - kill dry_run?
|
132
133
|
if dry_run?
|
133
134
|
totals = "This was a dry-run"
|
134
135
|
else
|
135
136
|
totals = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
|
136
|
-
totals << ", #{pending_count} pending" if pending_count > 0
|
137
|
+
totals << ", #{pending_count} pending" if pending_count > 0
|
137
138
|
end
|
138
139
|
@output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{duration} seconds</strong>\";</script>"
|
139
140
|
@output.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>"
|
@@ -144,10 +145,10 @@ module RSpec
|
|
144
145
|
@output.flush
|
145
146
|
end
|
146
147
|
|
147
|
-
def html_header
|
148
|
+
def html_header
|
148
149
|
<<-EOF
|
149
150
|
<?xml version="1.0" encoding="UTF-8"?>
|
150
|
-
<!DOCTYPE html
|
151
|
+
<!DOCTYPE html
|
151
152
|
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
152
153
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
153
154
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
@@ -220,7 +221,7 @@ function makeYellow(element_id) {
|
|
220
221
|
}
|
221
222
|
EOF
|
222
223
|
end
|
223
|
-
|
224
|
+
|
224
225
|
def global_styles
|
225
226
|
<<-EOF
|
226
227
|
#rspec-header {
|
@@ -5,14 +5,14 @@ module RSpec
|
|
5
5
|
class SnippetExtractor #:nodoc:
|
6
6
|
class NullConverter; def convert(code, pre); code; end; end #:nodoc:
|
7
7
|
begin; require 'syntax/convertors/html'; @@converter = Syntax::Convertors::HTML.for_syntax "ruby"; rescue LoadError => e; @@converter = NullConverter.new; end
|
8
|
-
|
8
|
+
|
9
9
|
def snippet(error)
|
10
10
|
raw_code, line = snippet_for(error.backtrace[0])
|
11
11
|
highlighted = @@converter.convert(raw_code, false)
|
12
12
|
highlighted << "\n<span class=\"comment\"># gem install syntax to get syntax highlighting</span>" if @@converter.is_a?(NullConverter)
|
13
13
|
post_process(highlighted, line)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def snippet_for(error_line)
|
17
17
|
if error_line =~ /(.*):(\d+)/
|
18
18
|
file = $1
|
@@ -22,7 +22,7 @@ module RSpec
|
|
22
22
|
["# Couldn't get snippet for #{error_line}", 1]
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def lines_around(file, line)
|
27
27
|
if File.file?(file)
|
28
28
|
lines = File.open(file).read.split("\n")
|
@@ -35,7 +35,7 @@ module RSpec
|
|
35
35
|
"# Couldn't get snippet for #{file}"
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def post_process(highlighted, offending_line)
|
40
40
|
new_lines = []
|
41
41
|
highlighted.split("\n").each_with_index do |line, i|
|
@@ -45,7 +45,7 @@ module RSpec
|
|
45
45
|
end
|
46
46
|
new_lines.join("\n")
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
data/lib/rspec/core/hooks.rb
CHANGED
@@ -80,10 +80,10 @@ module RSpec
|
|
80
80
|
class AroundHooks < HookCollection; end
|
81
81
|
|
82
82
|
def hooks
|
83
|
-
@hooks ||= {
|
83
|
+
@hooks ||= {
|
84
84
|
:around => { :each => AroundHooks.new },
|
85
|
-
:before => { :each => BeforeHooks.new, :all => BeforeHooks.new, :suite => BeforeHooks.new },
|
86
|
-
:after => { :each => AfterHooks.new, :all => AfterHooks.new, :suite => AfterHooks.new }
|
85
|
+
:before => { :each => BeforeHooks.new, :all => BeforeHooks.new, :suite => BeforeHooks.new },
|
86
|
+
:after => { :each => AfterHooks.new, :all => AfterHooks.new, :suite => AfterHooks.new }
|
87
87
|
}
|
88
88
|
end
|
89
89
|
|
data/lib/rspec/core/let.rb
CHANGED
@@ -4,7 +4,7 @@ module RSpec
|
|
4
4
|
|
5
5
|
module ClassMethods
|
6
6
|
# Generates a method whose return value is memoized
|
7
|
-
# after the first call.
|
7
|
+
# after the first call.
|
8
8
|
#
|
9
9
|
# == Examples
|
10
10
|
#
|
@@ -13,7 +13,7 @@ module RSpec
|
|
13
13
|
#
|
14
14
|
# it "does something" do
|
15
15
|
# # first invocation, executes block, memoizes and returns result
|
16
|
-
# thing.do_something
|
16
|
+
# thing.do_something
|
17
17
|
#
|
18
18
|
# # second invocation, returns the memoized value
|
19
19
|
# thing.should be_something
|
@@ -36,7 +36,7 @@ module RSpec
|
|
36
36
|
# def self.count
|
37
37
|
# @count ||= 0
|
38
38
|
# end
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# def self.count=(val)
|
41
41
|
# @count += val
|
42
42
|
# end
|
@@ -72,7 +72,7 @@ module RSpec
|
|
72
72
|
# it "is invoked implicitly" do
|
73
73
|
# Thing.count.should == 1
|
74
74
|
# end
|
75
|
-
#
|
75
|
+
#
|
76
76
|
# it "returns memoized version on first invocation" do
|
77
77
|
# thing
|
78
78
|
# Thing.count.should == 1
|
@@ -81,7 +81,7 @@ module RSpec
|
|
81
81
|
# end
|
82
82
|
def let!(name, &block)
|
83
83
|
let(name, &block)
|
84
|
-
before { __send__(name) }
|
84
|
+
before { __send__(name) }
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
data/lib/rspec/core/metadata.rb
CHANGED
@@ -49,7 +49,7 @@ module RSpec
|
|
49
49
|
#{"*"*50}
|
50
50
|
:#{key} is not allowed
|
51
51
|
|
52
|
-
RSpec reserves some hash keys for its own internal use,
|
52
|
+
RSpec reserves some hash keys for its own internal use,
|
53
53
|
including :#{key}, which is used on:
|
54
54
|
|
55
55
|
#{caller(0)[4]}.
|
@@ -157,7 +157,7 @@ EOM
|
|
157
157
|
line_number = file_and_line_number(metadata)[1] if file_and_line_number(metadata)
|
158
158
|
line_number && line_number.to_i
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
def location_from(metadata)
|
162
162
|
"#{metadata[:file_path]}:#{metadata[:line_number]}"
|
163
163
|
end
|
@@ -5,16 +5,16 @@ module RSpec
|
|
5
5
|
module Core
|
6
6
|
module MockFrameworkAdapter
|
7
7
|
|
8
|
-
# Mocha::Standalone was deprecated as of Mocha 0.9.7.
|
8
|
+
# Mocha::Standalone was deprecated as of Mocha 0.9.7.
|
9
9
|
begin
|
10
10
|
include Mocha::API
|
11
11
|
rescue NameError
|
12
12
|
include Mocha::Standalone
|
13
13
|
end
|
14
|
-
|
15
|
-
alias :
|
16
|
-
alias :
|
17
|
-
alias :
|
14
|
+
|
15
|
+
alias :setup_mocks_for_rspec :mocha_setup
|
16
|
+
alias :verify_mocks_for_rspec :mocha_verify
|
17
|
+
alias :teardown_mocks_for_rspec :mocha_teardown
|
18
18
|
|
19
19
|
end
|
20
20
|
end
|
@@ -8,15 +8,15 @@ module RSpec
|
|
8
8
|
|
9
9
|
include RR::Extensions::InstanceMethods
|
10
10
|
|
11
|
-
def
|
11
|
+
def setup_mocks_for_rspec
|
12
12
|
RR::Space.instance.reset
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def verify_mocks_for_rspec
|
16
16
|
RR::Space.instance.verify_doubles
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def teardown_mocks_for_rspec
|
20
20
|
RR::Space.instance.reset
|
21
21
|
end
|
22
22
|
|
@@ -4,15 +4,15 @@ module RSpec
|
|
4
4
|
module Core
|
5
5
|
module MockFrameworkAdapter
|
6
6
|
|
7
|
-
def
|
7
|
+
def setup_mocks_for_rspec
|
8
8
|
RSpec::Mocks::setup(self)
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def verify_mocks_for_rspec
|
12
12
|
RSpec::Mocks::verify
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def teardown_mocks_for_rspec
|
16
16
|
RSpec::Mocks::teardown
|
17
17
|
end
|
18
18
|
|
@@ -31,7 +31,7 @@ module RSpec::Core
|
|
31
31
|
parser.on('-c', '--[no-]color', '--[no-]colour', 'Enable color in the output') do |o|
|
32
32
|
options[:color_enabled] = o
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
parser.on('-d', '--debug', 'Enable debugging') do |o|
|
36
36
|
options[:debug] = true
|
37
37
|
end
|
@@ -50,7 +50,7 @@ module RSpec::Core
|
|
50
50
|
options[:formatter] = o
|
51
51
|
end
|
52
52
|
|
53
|
-
parser.on_tail('-h', '--help', "You're looking at it.") do
|
53
|
+
parser.on_tail('-h', '--help', "You're looking at it.") do
|
54
54
|
puts parser
|
55
55
|
exit
|
56
56
|
end
|
@@ -67,7 +67,7 @@ module RSpec::Core
|
|
67
67
|
parser.on('-o', '--options PATH', 'Read configuration options from a file path. (Defaults to .rspec)') do |o|
|
68
68
|
options[:options_file] = o || local_options_file
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
parser.on('-p', '--profile', 'Enable profiling of examples with output of the top 10 slowest examples') do |o|
|
72
72
|
options[:profile_examples] = o
|
73
73
|
end
|
@@ -86,10 +86,14 @@ module RSpec::Core
|
|
86
86
|
options[:drb] = true
|
87
87
|
end
|
88
88
|
|
89
|
+
parser.on('--configure COMMAND', 'Generate configuration files') do |cmd|
|
90
|
+
CommandLineConfiguration.new(cmd).run
|
91
|
+
exit
|
92
|
+
end
|
93
|
+
|
89
94
|
parser.on('--drb-port [PORT]', 'Port to connect to on the DRb server') do |o|
|
90
95
|
options[:drb_port] = o.to_i
|
91
96
|
end
|
92
|
-
|
93
97
|
end
|
94
98
|
end
|
95
99
|
end
|
data/lib/rspec/core/rake_task.rb
CHANGED
@@ -18,6 +18,9 @@ module RSpec
|
|
18
18
|
# Glob pattern to match files. (default is 'spec/**/*_spec.rb')
|
19
19
|
attr_accessor :pattern
|
20
20
|
|
21
|
+
# Array of commandline options to pass to RSpec. Defaults to [].
|
22
|
+
attr_accessor :spec_opts
|
23
|
+
|
21
24
|
# The options to pass to ruby. Defaults to blank
|
22
25
|
attr_accessor :ruby_opts
|
23
26
|
|
@@ -46,6 +49,7 @@ module RSpec
|
|
46
49
|
@pattern, @rcov_path, @rcov_opts, @ruby_opts = nil, nil, nil, nil
|
47
50
|
@warning, @rcov = false, false
|
48
51
|
@fail_on_error = true
|
52
|
+
@spec_opts = []
|
49
53
|
|
50
54
|
yield self if block_given?
|
51
55
|
@rcov_path ||= 'rcov'
|
@@ -88,6 +92,7 @@ module RSpec
|
|
88
92
|
cmd_parts.unshift runner
|
89
93
|
cmd_parts.unshift bundler
|
90
94
|
cmd_parts += files_to_run.map { |fn| %["#{fn}"] }
|
95
|
+
cmd_parts << spec_opts.join(" ")
|
91
96
|
cmd_parts.join(" ")
|
92
97
|
end
|
93
98
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Core
|
3
3
|
module SharedExampleGroup
|
4
|
-
|
4
|
+
|
5
5
|
def share_examples_for(name, &block)
|
6
6
|
ensure_shared_example_group_name_not_taken(name)
|
7
7
|
RSpec.world.shared_example_groups[name] = block
|
@@ -12,7 +12,7 @@ module RSpec
|
|
12
12
|
mod = Object.const_get(name)
|
13
13
|
raise_name_error unless mod.created_from_caller(caller)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
mod = Module.new do
|
17
17
|
@shared_block = block
|
18
18
|
@caller_line = caller.last
|
data/lib/rspec/core/subject.rb
CHANGED
@@ -3,9 +3,11 @@ module RSpec
|
|
3
3
|
module Subject
|
4
4
|
|
5
5
|
def self.included(kls)
|
6
|
-
kls.
|
7
|
-
|
8
|
-
|
6
|
+
kls.class_eval do
|
7
|
+
extend ClassMethods
|
8
|
+
alias_method :__should_for_example_group__, :should
|
9
|
+
alias_method :__should_not_for_example_group__, :should_not
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
13
|
def subject
|
@@ -80,7 +82,11 @@ module RSpec
|
|
80
82
|
end
|
81
83
|
|
82
84
|
def attribute_of_subject
|
83
|
-
|
85
|
+
if using_attribute?
|
86
|
+
example.description.split('.').inject(original_subject) do |target, method|
|
87
|
+
target.send(method)
|
88
|
+
end
|
89
|
+
end
|
84
90
|
end
|
85
91
|
|
86
92
|
def using_attribute?
|