rspec-longrun 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +63 -0
- data/Rakefile +11 -0
- data/lib/rspec/longrun.rb +4 -0
- data/lib/rspec/longrun/dsl.rb +58 -0
- data/lib/rspec/longrun/formatter.rb +74 -0
- data/lib/rspec/longrun/version.rb +5 -0
- data/rspec-longrun.gemspec +18 -0
- data/spec/rspec/longrun/formatter_spec.rb +120 -0
- metadata +80 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-r rspec/longrun -f RSpec::Longrun::Formatter --color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Mike Williams
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# RSpec::Longrun
|
2
|
+
|
3
|
+
RSpec is a fine unit-testing framework, but is also handy for acceptance and integration tests. But the default report formatters make it difficult to track progress of such long-running tests.
|
4
|
+
|
5
|
+
The RSpec::Longrun::Formatter outputs the name of each test as it starts, rather than waiting until it passes or fails. It also provides a mechanism for reporting on progress of a test while it is still executing.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'rspec-longrun'
|
12
|
+
|
13
|
+
In a Rails project, you can safely limit it to the "test" group.
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Running tests
|
18
|
+
|
19
|
+
Specify the custom output format when invoking RSpec, as follows:
|
20
|
+
|
21
|
+
rspec -r rspec/longrun -f RSpec::Longrun::Formatter spec ...
|
22
|
+
|
23
|
+
The resulting test output looks something like:
|
24
|
+
|
25
|
+
Example group
|
26
|
+
First example
|
27
|
+
OK
|
28
|
+
Second example
|
29
|
+
OK
|
30
|
+
Third example
|
31
|
+
PENDING (Not implemented yet)
|
32
|
+
|
33
|
+
### Tracking progress
|
34
|
+
|
35
|
+
RSpec::Longrun defines a 'step' method that can be used to group blocks of code within the context of a large test. For example:
|
36
|
+
|
37
|
+
example "Log in and alter preferences" do
|
38
|
+
|
39
|
+
step "Log in" do
|
40
|
+
# ...
|
41
|
+
end
|
42
|
+
|
43
|
+
step "Navigate to preferences page" do
|
44
|
+
# ...
|
45
|
+
end
|
46
|
+
|
47
|
+
step "Change preferences" do
|
48
|
+
# ...
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
The resulting test output looks something like:
|
54
|
+
|
55
|
+
Log in and alter preferences
|
56
|
+
- Log in
|
57
|
+
- Navigate to preferences page
|
58
|
+
- Change preferences
|
59
|
+
OK
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
rspec-longrun is on Github. You know what to do.
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rspec/core/example'
|
2
|
+
require 'rspec/core/example_group'
|
3
|
+
require 'rspec/core/formatters/base_formatter'
|
4
|
+
require 'rspec/core/reporter'
|
5
|
+
|
6
|
+
# extend rspec-core with support for "steps"
|
7
|
+
|
8
|
+
module RSpec::Core
|
9
|
+
|
10
|
+
class Reporter
|
11
|
+
|
12
|
+
def step_started(description)
|
13
|
+
notify :step_started, description
|
14
|
+
end
|
15
|
+
|
16
|
+
def step_finished(description)
|
17
|
+
notify :step_finished, description
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
class Formatters::BaseFormatter
|
23
|
+
|
24
|
+
def step_started(description)
|
25
|
+
end
|
26
|
+
|
27
|
+
def step_finished(description)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
class Example
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
alias :start_without_reporter :start
|
37
|
+
|
38
|
+
def start(reporter)
|
39
|
+
start_without_reporter(reporter)
|
40
|
+
@example_group_instance.instance_variable_set(:@_rspec_reporter, reporter)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
class ExampleGroup
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def step(description)
|
50
|
+
@_rspec_reporter.step_started(description)
|
51
|
+
yield if block_given?
|
52
|
+
ensure
|
53
|
+
@_rspec_reporter.step_finished(description)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "rspec/core/formatters/base_text_formatter"
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Longrun
|
5
|
+
|
6
|
+
class Formatter < RSpec::Core::Formatters::BaseTextFormatter
|
7
|
+
|
8
|
+
def initialize(output)
|
9
|
+
super(output)
|
10
|
+
@indent_level = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def example_group_started(example_group)
|
14
|
+
super(example_group)
|
15
|
+
start_block(example_group.description)
|
16
|
+
end
|
17
|
+
|
18
|
+
def example_group_finished(example_group)
|
19
|
+
super(example_group)
|
20
|
+
end_block
|
21
|
+
end
|
22
|
+
|
23
|
+
def example_started(example)
|
24
|
+
super(example)
|
25
|
+
start_block(example.description)
|
26
|
+
end
|
27
|
+
|
28
|
+
def example_passed(example)
|
29
|
+
super(example)
|
30
|
+
end_block(green("OK"))
|
31
|
+
end
|
32
|
+
|
33
|
+
def example_pending(example)
|
34
|
+
super(example)
|
35
|
+
end_block(yellow("PENDING (#{example.execution_result[:pending_message]})"))
|
36
|
+
end
|
37
|
+
|
38
|
+
def example_failed(example)
|
39
|
+
super(example)
|
40
|
+
end_block(red("FAILED"))
|
41
|
+
end
|
42
|
+
|
43
|
+
def step_started(description)
|
44
|
+
start_block('- ' + description)
|
45
|
+
end
|
46
|
+
|
47
|
+
def step_finished(description)
|
48
|
+
end_block
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def start_block(message)
|
54
|
+
emit(message.strip)
|
55
|
+
@indent_level += 1
|
56
|
+
end
|
57
|
+
|
58
|
+
def end_block(message = nil)
|
59
|
+
emit(message.strip) if message
|
60
|
+
@indent_level -= 1
|
61
|
+
end
|
62
|
+
|
63
|
+
def emit(message)
|
64
|
+
output.puts(message.gsub(/^/, current_indentation))
|
65
|
+
end
|
66
|
+
|
67
|
+
def current_indentation
|
68
|
+
' ' * @indent_level
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rspec/longrun/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mike Williams"]
|
6
|
+
gem.email = ["mdub@dogbiscuit.org"]
|
7
|
+
gem.summary = "An RSpec formatter for long-running specs."
|
8
|
+
gem.homepage = "http://github.com/mdub/rspec-longrun"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
|
+
gem.name = "rspec-longrun"
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.version = RSpec::Longrun::VERSION
|
15
|
+
|
16
|
+
gem.add_runtime_dependency("rspec-core", ">= 2.10.0")
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require "rspec/longrun"
|
2
|
+
require "stringio"
|
3
|
+
|
4
|
+
describe RSpec::Longrun::Formatter do
|
5
|
+
|
6
|
+
let(:output_buffer) { StringIO.new }
|
7
|
+
let(:formatter) { described_class.new(output_buffer) }
|
8
|
+
|
9
|
+
def undent(raw)
|
10
|
+
if raw =~ /\A( +)/
|
11
|
+
indent = $1
|
12
|
+
raw.gsub(/^#{indent}/, '').gsub(/ +$/, '')
|
13
|
+
else
|
14
|
+
raw
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def output
|
19
|
+
output_buffer.string
|
20
|
+
end
|
21
|
+
|
22
|
+
module NoColor
|
23
|
+
|
24
|
+
def color_enabled?
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
before do
|
31
|
+
formatter.extend(NoColor)
|
32
|
+
suite.run(formatter)
|
33
|
+
end
|
34
|
+
|
35
|
+
context "for nested example groups" do
|
36
|
+
|
37
|
+
let(:suite) do
|
38
|
+
RSpec::Core::ExampleGroup.describe("foo") do
|
39
|
+
describe "bar" do
|
40
|
+
describe "baz" do
|
41
|
+
end
|
42
|
+
end
|
43
|
+
describe "qux" do
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "outputs nested group name" do
|
49
|
+
output.should eql(undent(<<-EOF))
|
50
|
+
foo
|
51
|
+
bar
|
52
|
+
baz
|
53
|
+
qux
|
54
|
+
EOF
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with examples" do
|
60
|
+
|
61
|
+
let(:suite) do
|
62
|
+
RSpec::Core::ExampleGroup.describe("suite") do
|
63
|
+
example "works" do; end
|
64
|
+
example "is unimplemented" do
|
65
|
+
pending "implement me"
|
66
|
+
end
|
67
|
+
example "fails" do
|
68
|
+
fail "no worky"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "outputs example names and status" do
|
74
|
+
output.should eql(undent(<<-EOF))
|
75
|
+
suite
|
76
|
+
works
|
77
|
+
OK
|
78
|
+
is unimplemented
|
79
|
+
PENDING (implement me)
|
80
|
+
fails
|
81
|
+
FAILED
|
82
|
+
EOF
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
context "with steps" do
|
88
|
+
|
89
|
+
let(:suite) do
|
90
|
+
RSpec::Core::ExampleGroup.describe("suite") do
|
91
|
+
example "has steps" do
|
92
|
+
step "Collect underpants" do
|
93
|
+
end
|
94
|
+
step "Er ..." do
|
95
|
+
step "(thinking)" do
|
96
|
+
end
|
97
|
+
end
|
98
|
+
step "Profit!" do
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "outputs steps" do
|
105
|
+
step "try steps" do
|
106
|
+
output.should eql(undent(<<-EOF))
|
107
|
+
suite
|
108
|
+
has steps
|
109
|
+
- Collect underpants
|
110
|
+
- Er ...
|
111
|
+
- (thinking)
|
112
|
+
- Profit!
|
113
|
+
OK
|
114
|
+
EOF
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-longrun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mike Williams
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec-core
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.10.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.10.0
|
30
|
+
description:
|
31
|
+
email:
|
32
|
+
- mdub@dogbiscuit.org
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rspec
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/rspec/longrun.rb
|
44
|
+
- lib/rspec/longrun/dsl.rb
|
45
|
+
- lib/rspec/longrun/formatter.rb
|
46
|
+
- lib/rspec/longrun/version.rb
|
47
|
+
- rspec-longrun.gemspec
|
48
|
+
- spec/rspec/longrun/formatter_spec.rb
|
49
|
+
homepage: http://github.com/mdub/rspec-longrun
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
hash: -754123683182328035
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
hash: -754123683182328035
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.23
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: An RSpec formatter for long-running specs.
|
79
|
+
test_files:
|
80
|
+
- spec/rspec/longrun/formatter_spec.rb
|