rspec 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +12 -0
- data/Rakefile +13 -2
- data/examples/custom_formatter.rb +8 -19
- data/examples/mocking_example.rb +0 -1
- data/lib/spec/mocks/message_expectation.rb +6 -1
- data/lib/spec/runner.rb +1 -0
- data/lib/spec/runner/command_line.rb +2 -2
- data/lib/spec/runner/extensions/kernel.rb +1 -1
- data/lib/spec/runner/formatter/base_text_formatter.rb +10 -5
- data/lib/spec/runner/formatter/html_formatter.rb +44 -1
- data/lib/spec/runner/option_parser.rb +39 -4
- data/lib/spec/runner/spec_parser.rb +40 -0
- data/lib/spec/version.rb +3 -3
- metadata +4 -3
data/CHANGES
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
= RSpec Changelog
|
2
2
|
|
3
|
+
== Version 0.7.2 (in SVN)
|
4
|
+
|
5
|
+
This release introduces a brand new RSpec bundle for TextMate, plus some small bugfixes.
|
6
|
+
|
7
|
+
* Packaged RSpec.tmbundle.tgz as part of the distro
|
8
|
+
* Fixed [#6593] Add moving progress bar to HtmlFormatter using Javascript
|
9
|
+
* Applied [#6265] should_raise should accept an Exception object
|
10
|
+
* Fixed [#6616] Can't run Rails specs with RSpec.tmbundle
|
11
|
+
* Fixed [#6411] Can't run Rails specs with ruby
|
12
|
+
* Added [#6589] New -l --line option. This is useful for IDE/editor runners/extensions.
|
13
|
+
* Fixed [#6615] controller.should_render_rjs should support :partial => 'path/to/template'
|
14
|
+
|
3
15
|
== Version 0.7.1
|
4
16
|
|
5
17
|
Bug fixes and a couple o' new features.
|
data/Rakefile
CHANGED
@@ -32,7 +32,7 @@ task :default => [:spec, :verify_rcov]
|
|
32
32
|
|
33
33
|
desc "Run all specs"
|
34
34
|
Spec::Rake::SpecTask.new do |t|
|
35
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
35
|
+
t.spec_files = FileList['spec/**/*_spec.rb', 'vendor/RSpec.tmbundle/Support/spec/*_spec.rb']
|
36
36
|
t.spec_opts = ['--diff','--color','--backtrace']
|
37
37
|
t.rcov = true
|
38
38
|
t.rcov_dir = 'doc/output/coverage'
|
@@ -224,6 +224,16 @@ task :publish_website => [:verify_user, :website] do
|
|
224
224
|
publisher.upload
|
225
225
|
end
|
226
226
|
|
227
|
+
desc "Package the RSpec.tmbundle"
|
228
|
+
task :package_tmbundle => :pkg do
|
229
|
+
rm_rf 'pkg/RSpec.tmbundle'
|
230
|
+
`svn export vendor/RSpec.tmbundle pkg/RSpec.tmbundle`
|
231
|
+
Dir.chdir 'pkg' do
|
232
|
+
`tar cvzf RSpec-#{PKG_VERSION}.tmbundle.tgz RSpec.tmbundle`
|
233
|
+
end
|
234
|
+
end
|
235
|
+
task :package => :package_tmbundle
|
236
|
+
|
227
237
|
desc "Publish gem+tgz+zip on RubyForge. You must make sure lib/version.rb is aligned with the CHANGELOG file"
|
228
238
|
task :publish_packages => [:verify_user, :verify_password, :package] do
|
229
239
|
require 'meta_project'
|
@@ -231,7 +241,8 @@ task :publish_packages => [:verify_user, :verify_password, :package] do
|
|
231
241
|
release_files = FileList[
|
232
242
|
"pkg/#{PKG_FILE_NAME}.gem",
|
233
243
|
"pkg/#{PKG_FILE_NAME}.tgz",
|
234
|
-
"pkg/#{PKG_FILE_NAME}.zip"
|
244
|
+
"pkg/#{PKG_FILE_NAME}.zip",
|
245
|
+
"pkg/RSpec-#{PKG_VERSION}.tmbundle.tgz"
|
235
246
|
]
|
236
247
|
|
237
248
|
Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new(PKG_NAME)) do |xf|
|
@@ -1,22 +1,11 @@
|
|
1
|
-
require 'spec/runner/formatter/
|
1
|
+
require 'spec/runner/formatter/progress_bar_formatter'
|
2
2
|
|
3
|
-
# Example of a custom
|
4
|
-
# bin/spec
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def spec_failed(name, counter, failure)
|
12
|
-
@output.print 'X'
|
13
|
-
end
|
14
|
-
|
15
|
-
def spec_passed(name)
|
16
|
-
@output.print '_'
|
17
|
-
end
|
18
|
-
|
19
|
-
def start_dump
|
20
|
-
@output.print "\n"
|
3
|
+
# Example of a formatter with custom bactrace printing. Run me with:
|
4
|
+
# ruby bin/spec failing_examples -r examples/custom_formatter.rb -f CustomFormatter
|
5
|
+
class CustomFormatter < Spec::Runner::Formatter::ProgressBarFormatter
|
6
|
+
def backtrace_line(line)
|
7
|
+
line.gsub(/([^:]*\.rb):(\d*)/) do
|
8
|
+
"<a href=\"file://#{File.expand_path($1)}\">#{$1}:#{$2}</a> "
|
9
|
+
end
|
21
10
|
end
|
22
11
|
end
|
data/examples/mocking_example.rb
CHANGED
@@ -49,7 +49,12 @@ module Spec
|
|
49
49
|
@order_group.handle_order_constraint self
|
50
50
|
|
51
51
|
begin
|
52
|
-
|
52
|
+
if @exception_to_raise.class == Class
|
53
|
+
@exception_instance_to_raise = @exception_to_raise.new
|
54
|
+
else
|
55
|
+
@exception_instance_to_raise = @exception_to_raise
|
56
|
+
end
|
57
|
+
Kernel::raise @exception_to_raise unless @exception_to_raise.nil?
|
53
58
|
Kernel::throw @symbol_to_throw unless @symbol_to_throw.nil?
|
54
59
|
|
55
60
|
if !@method_block.nil?
|
data/lib/spec/runner.rb
CHANGED
@@ -7,9 +7,9 @@ module Spec
|
|
7
7
|
# not a system exit should be called after the specs are run and
|
8
8
|
# +warn_if_no_files+ tells whether or not a warning (the help message)
|
9
9
|
# should be printed to +stderr+ in case no files are specified.
|
10
|
-
def self.run(argv, stderr, stdout, exit, warn_if_no_files)
|
10
|
+
def self.run(argv, stderr, stdout, exit=false, warn_if_no_files=true)
|
11
11
|
old_context_runner = defined?($context_runner) ? $context_runner : nil
|
12
|
-
$context_runner = OptionParser.create_context_runner(argv, stderr, stdout, warn_if_no_files)
|
12
|
+
$context_runner = OptionParser.new.create_context_runner(argv, stderr, stdout, warn_if_no_files)
|
13
13
|
|
14
14
|
# If ARGV is a glob, it will actually each over each one of the matching files.
|
15
15
|
argv.each do |file_or_dir|
|
@@ -7,7 +7,7 @@ module Kernel
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def context_runner
|
10
|
-
if $context_runner.nil?; $context_runner = ::Spec::Runner::OptionParser.create_context_runner(ARGV.dup, STDERR, STDOUT, false); at_exit { $context_runner.run(false) }; end
|
10
|
+
if $context_runner.nil?; $context_runner = ::Spec::Runner::OptionParser.new.create_context_runner(ARGV.dup, STDERR, STDOUT, false); at_exit { $context_runner.run(false) }; end
|
11
11
|
$context_runner
|
12
12
|
end
|
13
13
|
end
|
@@ -66,7 +66,7 @@ module Spec
|
|
66
66
|
@output.puts magenta(failure.header)
|
67
67
|
@output.puts magenta(failure.exception.message)
|
68
68
|
end
|
69
|
-
@output.puts failure.exception.backtrace
|
69
|
+
@output.puts format_backtrace(failure.exception.backtrace)
|
70
70
|
STDOUT.flush
|
71
71
|
end
|
72
72
|
|
@@ -84,8 +84,17 @@ module Spec
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
def format_backtrace(backtrace)
|
88
|
+
return "" if backtrace.nil?
|
89
|
+
backtrace.map { |line| backtrace_line(line) }.join("\n")
|
90
|
+
end
|
91
|
+
|
87
92
|
protected
|
88
93
|
|
94
|
+
def backtrace_line(line)
|
95
|
+
line
|
96
|
+
end
|
97
|
+
|
89
98
|
def colour(text, colour_code)
|
90
99
|
return text unless @colour && @output == Kernel
|
91
100
|
"#{colour_code}#{text}\e[0m"
|
@@ -95,10 +104,6 @@ module Spec
|
|
95
104
|
def green(text); colour(text, "\e[32m"); end
|
96
105
|
def magenta(text); colour(text, "\e[35m"); end
|
97
106
|
|
98
|
-
def format_backtrace(backtrace)
|
99
|
-
backtrace.nil? ? "" : backtrace.join("\n")
|
100
|
-
end
|
101
|
-
|
102
107
|
end
|
103
108
|
end
|
104
109
|
end
|
@@ -5,6 +5,7 @@ module Spec
|
|
5
5
|
def initialize(output, dry_run=false, colour=false)
|
6
6
|
super
|
7
7
|
@current_count = 0
|
8
|
+
@spec_count = 0
|
8
9
|
end
|
9
10
|
|
10
11
|
def start(spec_count)
|
@@ -22,6 +23,7 @@ module Spec
|
|
22
23
|
@output.puts "<div class=\"context\">"
|
23
24
|
@output.puts " <ul>"
|
24
25
|
@output.puts " <li class=\"context_name\">#{name}</li>"
|
26
|
+
STDOUT.flush
|
25
27
|
end
|
26
28
|
|
27
29
|
def start_dump
|
@@ -33,13 +35,18 @@ module Spec
|
|
33
35
|
def spec_started(name)
|
34
36
|
@current_spec = name
|
35
37
|
@current_count += 1
|
38
|
+
STDOUT.flush
|
36
39
|
end
|
37
40
|
|
38
41
|
def spec_passed(name)
|
42
|
+
move_progress
|
39
43
|
@output.puts " <li class=\"spec passed\"><div class=\"passed_spec_name\">#{escape(@current_spec)}</div></li>"
|
44
|
+
STDOUT.flush
|
40
45
|
end
|
41
46
|
|
42
47
|
def spec_failed(name, counter, failure)
|
48
|
+
@output.puts " <script type=\"text/javascript\">makeProgressbarRed();</script>"
|
49
|
+
move_progress
|
43
50
|
@output.puts " <li class=\"spec failed\">"
|
44
51
|
@output.puts " <div class=\"failed_spec_name\">#{escape(@current_spec)}</div>"
|
45
52
|
@output.puts " <div class=\"failure\" id=\"failure_#{counter}\">"
|
@@ -50,6 +57,11 @@ module Spec
|
|
50
57
|
STDOUT.flush
|
51
58
|
end
|
52
59
|
|
60
|
+
def move_progress
|
61
|
+
percent_done = @spec_count == 0 ? 100.0 : (@current_count.to_f / @spec_count.to_f * 1000).to_i / 10.0
|
62
|
+
@output.puts " <script type=\"text/javascript\">moveProgressBar('#{percent_done}');</script>"
|
63
|
+
end
|
64
|
+
|
53
65
|
def escape(string)
|
54
66
|
string.gsub(/&/n, '&').gsub(/\"/n, '"').gsub(/>/n, '>').gsub(/</n, '<')
|
55
67
|
end
|
@@ -63,6 +75,9 @@ module Spec
|
|
63
75
|
STDOUT.flush
|
64
76
|
end
|
65
77
|
|
78
|
+
RED_BACKGROUND = '#CD0000'
|
79
|
+
GREEN_BACKGROUND = '#659D32'
|
80
|
+
|
66
81
|
HEADER = <<-HEADER
|
67
82
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
68
83
|
<!DOCTYPE html
|
@@ -74,6 +89,14 @@ module Spec
|
|
74
89
|
<title>RSpec results</title>
|
75
90
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
76
91
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
92
|
+
<script type="text/javascript">
|
93
|
+
function moveProgressBar(percentDone) {
|
94
|
+
document.getElementById("progress-bar").style.width = percentDone +"%";
|
95
|
+
}
|
96
|
+
function makeProgressbarRed() {
|
97
|
+
document.getElementById('progress-bar').style.background = '#{RED_BACKGROUND}';
|
98
|
+
}
|
99
|
+
</script>
|
77
100
|
<style type="text/css">
|
78
101
|
body {
|
79
102
|
font-size: 9pt;
|
@@ -81,6 +104,17 @@ module Spec
|
|
81
104
|
width: 85%;
|
82
105
|
}
|
83
106
|
|
107
|
+
#progress-bar-bg {
|
108
|
+
background-color: #C9C9C9;
|
109
|
+
border-bottom: 1px solid gray;
|
110
|
+
border-right: 1px solid gray;
|
111
|
+
}
|
112
|
+
|
113
|
+
#progress-bar {
|
114
|
+
background-color: #{GREEN_BACKGROUND};
|
115
|
+
width: 0px;
|
116
|
+
}
|
117
|
+
|
84
118
|
div.context {
|
85
119
|
padding: 0px;
|
86
120
|
background: #fff;
|
@@ -132,12 +166,21 @@ module Spec
|
|
132
166
|
}
|
133
167
|
|
134
168
|
div.backtrace {
|
135
|
-
color: #
|
169
|
+
color: #fff;
|
170
|
+
}
|
171
|
+
|
172
|
+
div.backtrace a {
|
173
|
+
color: #fff;
|
136
174
|
}
|
137
175
|
|
138
176
|
</style>
|
139
177
|
</head>
|
140
178
|
<body>
|
179
|
+
|
180
|
+
<div id="progress-bar-bg">
|
181
|
+
<div id="progress-bar"> </div>
|
182
|
+
</div>
|
183
|
+
|
141
184
|
HEADER
|
142
185
|
end
|
143
186
|
end
|
@@ -4,8 +4,12 @@ require 'optparse'
|
|
4
4
|
module Spec
|
5
5
|
module Runner
|
6
6
|
class OptionParser
|
7
|
+
def initialize
|
8
|
+
@spec_parser = SpecParser.new
|
9
|
+
@file_factory = File
|
10
|
+
end
|
7
11
|
|
8
|
-
def
|
12
|
+
def create_context_runner(args, err, out, warn_if_no_files)
|
9
13
|
options = parse(args, err, out, warn_if_no_files)
|
10
14
|
|
11
15
|
formatter = options.formatter_type.new(options.out, options.dry_run, options.colour)
|
@@ -20,7 +24,7 @@ module Spec
|
|
20
24
|
ContextRunner.new(reporter, options.dry_run, options.spec_name)
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
27
|
+
def parse(args, err, out, warn_if_no_files)
|
24
28
|
options = OpenStruct.new
|
25
29
|
options.out = out == STDOUT ? Kernel : out
|
26
30
|
options.formatter_type = Formatter::ProgressBarFormatter
|
@@ -67,10 +71,14 @@ module Spec
|
|
67
71
|
options.colour = true
|
68
72
|
end
|
69
73
|
|
70
|
-
opts.on("-s", "--spec SPECIFICATION_NAME", "Execute
|
74
|
+
opts.on("-s", "--spec SPECIFICATION_NAME", "Execute context or specification with matching name") do |spec_name|
|
71
75
|
options.spec_name = spec_name
|
72
76
|
end
|
73
77
|
|
78
|
+
opts.on("-l", "--line LINE_NUMBER", Integer, "Execute context or specification at given line") do |line_number|
|
79
|
+
options.line_number = line_number.to_i
|
80
|
+
end
|
81
|
+
|
74
82
|
opts.on("-f", "--format FORMAT", "Builtin formats: specdoc|s|rdoc|r|html|h",
|
75
83
|
"You can also specify a custom formatter class",
|
76
84
|
"(in which case you should also specify --require)") do |format|
|
@@ -122,11 +130,38 @@ module Spec
|
|
122
130
|
|
123
131
|
if args.empty? && warn_if_no_files
|
124
132
|
err.puts opts
|
125
|
-
exit if err == $stderr
|
133
|
+
exit(1) if err == $stderr
|
134
|
+
end
|
135
|
+
|
136
|
+
if options.line_number
|
137
|
+
set_spec_from_line_number(options, args, err)
|
126
138
|
end
|
127
139
|
|
128
140
|
options
|
129
141
|
end
|
142
|
+
|
143
|
+
def set_spec_from_line_number(options, args, err)
|
144
|
+
unless options.spec_name
|
145
|
+
if args.length == 1
|
146
|
+
if @file_factory.file?(args[0])
|
147
|
+
source = @file_factory.open(args[0])
|
148
|
+
options.spec_name = @spec_parser.spec_name_for(source, options.line_number)
|
149
|
+
elsif @file_factory.directory?(args[0])
|
150
|
+
err.puts "You must specify one file, not a directory when using the --line option"
|
151
|
+
exit(1) if err == $stderr
|
152
|
+
else
|
153
|
+
err.puts "#{args[0]} does not exist"
|
154
|
+
exit(1) if err == $stderr
|
155
|
+
end
|
156
|
+
else
|
157
|
+
err.puts "Only one file can be specified when using the --line option"
|
158
|
+
exit(1) if err == $stderr
|
159
|
+
end
|
160
|
+
else
|
161
|
+
err.puts "You cannot use both --line and --spec"
|
162
|
+
exit(1) if err == $stderr
|
163
|
+
end
|
164
|
+
end
|
130
165
|
end
|
131
166
|
end
|
132
167
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Spec
|
2
|
+
module Runner
|
3
|
+
class SpecParser
|
4
|
+
def spec_name_for(io, line_number)
|
5
|
+
source = io.read
|
6
|
+
context = context_at_line(source, line_number)
|
7
|
+
spec = spec_at_line(source, line_number)
|
8
|
+
if context && spec
|
9
|
+
"#{context} #{spec}"
|
10
|
+
elsif context
|
11
|
+
context
|
12
|
+
else
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def context_at_line(source, line_number)
|
20
|
+
find_above(source, line_number, /^\s*context\s+['|"](.*)['|"]/)
|
21
|
+
end
|
22
|
+
|
23
|
+
def spec_at_line(source, line_number)
|
24
|
+
find_above(source, line_number, /^\s*specify\s+['|"](.*)['|"]/)
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_above(source, line_number, pattern)
|
28
|
+
lines_above_reversed(source, line_number).each do |line|
|
29
|
+
return $1 if line =~ pattern
|
30
|
+
end
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def lines_above_reversed(source, line_number)
|
35
|
+
lines = source.split("\n")
|
36
|
+
lines[0...line_number].reverse
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/spec/version.rb
CHANGED
@@ -3,9 +3,9 @@ module Spec
|
|
3
3
|
unless defined? MAJOR
|
4
4
|
MAJOR = 0
|
5
5
|
MINOR = 7
|
6
|
-
TINY =
|
7
|
-
# RANDOM_TOKEN: 0.
|
8
|
-
REV = "$LastChangedRevision:
|
6
|
+
TINY = 2
|
7
|
+
# RANDOM_TOKEN: 0.868668446220024
|
8
|
+
REV = "$LastChangedRevision: 1095 $".match(/LastChangedRevision: (\d+)/)[1]
|
9
9
|
|
10
10
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
11
11
|
FULL_VERSION = "#{STRING} (r#{REV})"
|
metadata
CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rspec
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.7.
|
7
|
-
date: 2006-11-
|
8
|
-
summary: RSpec-0.7.
|
6
|
+
version: 0.7.2
|
7
|
+
date: 2006-11-12 00:00:00 +01:00
|
8
|
+
summary: RSpec-0.7.2 (r1095) - BDD for Ruby http://rspec.rubyforge.org/
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: rspec-devel@rubyforge.org
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/spec/runner/option_parser.rb
|
79
79
|
- lib/spec/runner/reporter.rb
|
80
80
|
- lib/spec/runner/spec_matcher.rb
|
81
|
+
- lib/spec/runner/spec_parser.rb
|
81
82
|
- lib/spec/runner/spec_should_raise_handler.rb
|
82
83
|
- lib/spec/runner/specification.rb
|
83
84
|
- lib/spec/runner/extensions/kernel.rb
|