rspec-longrun 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +1 -5
- data/README.md +21 -16
- data/Rakefile +1 -1
- data/examples/example_spec.rb +1 -1
- data/examples/nested_spec.rb +13 -0
- data/examples/status_spec.rb +13 -0
- data/examples/stepped_spec.rb +21 -0
- data/lib/rspec/longrun/dsl.rb +25 -11
- data/lib/rspec/longrun/formatter.rb +31 -31
- data/lib/rspec/longrun/version.rb +1 -1
- data/rspec-longrun.gemspec +1 -1
- data/spec/rspec/longrun/formatter_spec.rb +73 -61
- metadata +17 -25
- data/lib/rspec/longrun/core_ext.rb +0 -50
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b7b0d901e0ecd2a67b69060390b5264b9f76b3790017bf6078e0dc58ad8149b9
|
4
|
+
data.tar.gz: ae6d4575321836e4543825ad7ef9f478a71ed763a78f663b58ffe128bf7ab53c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e1046bb744651efb275009ba7ddae501689ceab9e6702dbed4a4453d42250980fa82f47e345e0483545197f77d2f866a1f568b67560dff2877af10460793cd4
|
7
|
+
data.tar.gz: 04adfebac8fd026560a8dfb675a75f4b01eeb130dba732ff228acf7a5f0878982905ad1c57ea868ee666ba9d0117e701969dafbe665b0f5b0ac32a6b6ff9b3e1
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# RSpec::Longrun
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rspec-longrun.png)](http://badge.fury.io/rb/rspec-longrun)
|
4
|
+
[![Build Status](https://secure.travis-ci.org/mdub/rspec-longrun.png?branch=master)](http://travis-ci.org/mdub/rspec-longrun)
|
5
|
+
|
3
6
|
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
7
|
|
5
8
|
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.
|
@@ -34,29 +37,31 @@ The resulting test output looks something like:
|
|
34
37
|
|
35
38
|
Include RSpec::Longrun::DSL to define the 'step' method, which can be used to group blocks of code within the context of a large test. For example:
|
36
39
|
|
37
|
-
|
40
|
+
```ruby
|
41
|
+
describe "Account management" do
|
38
42
|
|
39
|
-
|
43
|
+
include RSpec::Longrun::DSL # <-- important
|
40
44
|
|
41
|
-
|
45
|
+
example "Log in and alter preferences" do
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
step "Log in" do
|
48
|
+
ui.go_home
|
49
|
+
ui.authenticate_as "joe", "fnord"
|
50
|
+
end
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
step "Navigate to preferences page" do
|
53
|
+
ui.nav.prefs_link.click
|
54
|
+
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
step "Change preferences" do
|
57
|
+
ui.prefs_pane.enter_defaults
|
58
|
+
ui.prefs_pane.save
|
59
|
+
end
|
56
60
|
|
57
|
-
|
61
|
+
end
|
58
62
|
|
59
|
-
|
63
|
+
end
|
64
|
+
```
|
60
65
|
|
61
66
|
The resulting test output looks something like:
|
62
67
|
|
data/Rakefile
CHANGED
data/examples/example_spec.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rspec/longrun'
|
3
|
+
|
4
|
+
RSpec.describe("stepped") do
|
5
|
+
|
6
|
+
include RSpec::Longrun::DSL
|
7
|
+
|
8
|
+
example "has steps" do
|
9
|
+
step "Collect underpants" do
|
10
|
+
end
|
11
|
+
step "Er ..." do
|
12
|
+
step "(thinking)" do
|
13
|
+
end
|
14
|
+
end
|
15
|
+
step "Profit!" do
|
16
|
+
pending "a real plan"
|
17
|
+
fail
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/rspec/longrun/dsl.rb
CHANGED
@@ -1,23 +1,37 @@
|
|
1
|
-
require 'rspec/longrun/core_ext'
|
2
|
-
|
3
|
-
# extend rspec-core with support for "steps"
|
4
|
-
|
5
1
|
module RSpec
|
6
2
|
module Longrun
|
7
3
|
module DSL
|
8
4
|
|
9
|
-
private
|
10
|
-
|
11
5
|
def step(description)
|
12
|
-
|
6
|
+
rspec_longrun_formatter.step_started(description)
|
13
7
|
begin
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
yield if block_given?
|
9
|
+
rspec_longrun_formatter.step_finished
|
10
|
+
rescue => e
|
11
|
+
rspec_longrun_formatter.step_errored(e)
|
12
|
+
raise e
|
18
13
|
end
|
19
14
|
end
|
20
15
|
|
16
|
+
private
|
17
|
+
|
18
|
+
def rspec_longrun_formatter
|
19
|
+
Thread.current["rspec.longrun.formatter"] || NullStepFormatter.new
|
20
|
+
end
|
21
|
+
|
22
|
+
class NullStepFormatter
|
23
|
+
|
24
|
+
def step_started(_description)
|
25
|
+
end
|
26
|
+
|
27
|
+
def step_finished
|
28
|
+
end
|
29
|
+
|
30
|
+
def step_errored(_e)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
21
35
|
end
|
22
36
|
end
|
23
37
|
end
|
@@ -5,64 +5,63 @@ module RSpec
|
|
5
5
|
|
6
6
|
class Formatter < RSpec::Core::Formatters::BaseTextFormatter
|
7
7
|
|
8
|
+
RSpec::Core::Formatters.register self,
|
9
|
+
:start,
|
10
|
+
:example_group_started, :example_group_finished,
|
11
|
+
:example_started, :example_passed,
|
12
|
+
:example_pending, :example_failed
|
13
|
+
|
8
14
|
def initialize(output)
|
9
15
|
super(output)
|
10
16
|
@blocks = [Block.new(true)]
|
11
17
|
end
|
12
18
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
19
|
+
def start(notification)
|
20
|
+
Thread.current["rspec.longrun.formatter"] = self
|
21
|
+
end
|
22
|
+
|
23
|
+
def example_group_started(notification)
|
24
|
+
begin_block(notification.group.description)
|
16
25
|
end
|
17
26
|
|
18
|
-
def example_group_finished(
|
19
|
-
super(example_group)
|
27
|
+
def example_group_finished(notification)
|
20
28
|
end_block
|
21
29
|
end
|
22
30
|
|
23
|
-
def example_started(
|
24
|
-
|
25
|
-
begin_block(detail_color(example.description))
|
31
|
+
def example_started(notification)
|
32
|
+
begin_block(wrap(notification.example.description, :detail))
|
26
33
|
end
|
27
34
|
|
28
|
-
def example_passed(
|
29
|
-
|
30
|
-
end_block(success_color("OK"))
|
35
|
+
def example_passed(notification)
|
36
|
+
end_block(wrap("OK", :success))
|
31
37
|
end
|
32
38
|
|
33
|
-
def example_pending(
|
34
|
-
|
35
|
-
end_block(pending_color("PENDING: " + example.execution_result[:pending_message]))
|
39
|
+
def example_pending(notification)
|
40
|
+
end_block(wrap("PENDING: " + notification.example.execution_result.pending_message, :pending))
|
36
41
|
end
|
37
42
|
|
38
|
-
def example_failed(
|
39
|
-
|
40
|
-
end_block(failure_color("FAILED"))
|
43
|
+
def example_failed(notification)
|
44
|
+
end_block(wrap("FAILED", :failure))
|
41
45
|
end
|
42
46
|
|
43
47
|
def step_started(description)
|
44
48
|
begin_block(description)
|
45
49
|
end
|
46
50
|
|
47
|
-
def step_finished
|
48
|
-
end_block
|
51
|
+
def step_finished
|
52
|
+
end_block(wrap("✓", :success))
|
49
53
|
end
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
def self.alias_missing_method(method_name, fallback_method_name)
|
54
|
-
unless method_defined?(method_name)
|
55
|
-
alias_method method_name, fallback_method_name
|
56
|
-
end
|
55
|
+
def step_errored(e)
|
56
|
+
end_block(wrap("✗", :failure))
|
57
57
|
end
|
58
58
|
|
59
|
-
alias_missing_method :detail_color, :cyan
|
60
|
-
alias_missing_method :success_color, :green
|
61
|
-
alias_missing_method :pending_color, :yellow
|
62
|
-
alias_missing_method :failure_color, :red
|
63
|
-
|
64
59
|
private
|
65
60
|
|
61
|
+
def wrap(*args)
|
62
|
+
RSpec::Core::Formatters::ConsoleCodes.wrap(*args)
|
63
|
+
end
|
64
|
+
|
66
65
|
def current_block
|
67
66
|
@blocks.last
|
68
67
|
end
|
@@ -98,7 +97,8 @@ module RSpec
|
|
98
97
|
end
|
99
98
|
|
100
99
|
def faint(text)
|
101
|
-
|
100
|
+
return text unless RSpec.configuration.color_enabled?
|
101
|
+
"\e[2m#{text}\e[0m"
|
102
102
|
end
|
103
103
|
|
104
104
|
class Block
|
data/rspec-longrun.gemspec
CHANGED
@@ -4,17 +4,6 @@ require "stringio"
|
|
4
4
|
describe RSpec::Longrun::Formatter do
|
5
5
|
|
6
6
|
let(:output_buffer) { StringIO.new }
|
7
|
-
let(:formatter) { described_class.new(output_buffer) }
|
8
|
-
let(:reporter) { RSpec::Core::Reporter.new(formatter) }
|
9
|
-
|
10
|
-
def undent(raw)
|
11
|
-
if raw =~ /\A( +)/
|
12
|
-
indent = $1
|
13
|
-
raw.gsub(/^#{indent}/, '').gsub(/ +$/, '')
|
14
|
-
else
|
15
|
-
raw
|
16
|
-
end
|
17
|
-
end
|
18
7
|
|
19
8
|
def output
|
20
9
|
output_buffer.string
|
@@ -24,46 +13,47 @@ describe RSpec::Longrun::Formatter do
|
|
24
13
|
output.gsub(/0\.\d\ds/, "N.NNs")
|
25
14
|
end
|
26
15
|
|
27
|
-
|
16
|
+
let(:formatter) { described_class.new(output_buffer) }
|
28
17
|
|
29
|
-
|
30
|
-
|
31
|
-
|
18
|
+
before do
|
19
|
+
allow(RSpec.configuration).to receive(:color_enabled?).and_return(false)
|
20
|
+
end
|
32
21
|
|
22
|
+
def example_group(desc)
|
23
|
+
notification = double(group: double(description: desc))
|
24
|
+
formatter.example_group_started(notification)
|
25
|
+
yield if block_given?
|
26
|
+
formatter.example_group_finished(notification)
|
33
27
|
end
|
34
28
|
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
def example(desc, result, pending_message = nil)
|
30
|
+
notification = double(
|
31
|
+
example: double(
|
32
|
+
description: desc,
|
33
|
+
execution_result: double(pending_message: pending_message)
|
34
|
+
)
|
35
|
+
)
|
36
|
+
formatter.example_started(notification)
|
37
|
+
yield if block_given?
|
38
|
+
formatter.public_send("example_#{result}", notification)
|
39
|
+
end
|
40
|
+
|
41
|
+
def step(desc)
|
42
|
+
formatter.step_started(desc)
|
43
|
+
yield if block_given?
|
44
|
+
formatter.step_finished
|
38
45
|
end
|
39
46
|
|
40
|
-
context "
|
47
|
+
context "given an empty example group" do
|
41
48
|
|
42
|
-
|
43
|
-
|
44
|
-
describe "bar" do
|
45
|
-
describe "baz" do
|
46
|
-
it "bleeds"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
describe "qux" do
|
50
|
-
it "hurts"
|
51
|
-
end
|
49
|
+
before do
|
50
|
+
example_group "suite" do
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
55
|
-
it "outputs
|
56
|
-
normalized_output.
|
57
|
-
|
58
|
-
bar {
|
59
|
-
baz {
|
60
|
-
bleeds PENDING: Not yet implemented (N.NNs)
|
61
|
-
} (N.NNs)
|
62
|
-
} (N.NNs)
|
63
|
-
qux {
|
64
|
-
hurts PENDING: Not yet implemented (N.NNs)
|
65
|
-
} (N.NNs)
|
66
|
-
} (N.NNs)
|
54
|
+
it "outputs suite entry" do
|
55
|
+
expect(normalized_output).to eql(<<~EOF)
|
56
|
+
suite (N.NNs)
|
67
57
|
EOF
|
68
58
|
end
|
69
59
|
|
@@ -71,24 +61,46 @@ describe RSpec::Longrun::Formatter do
|
|
71
61
|
|
72
62
|
context "with examples" do
|
73
63
|
|
74
|
-
|
75
|
-
|
76
|
-
example "works"
|
77
|
-
example "
|
78
|
-
|
79
|
-
end
|
80
|
-
example "fails" do
|
81
|
-
fail "no worky"
|
82
|
-
end
|
64
|
+
before do
|
65
|
+
example_group "suite" do
|
66
|
+
example "works", :passed
|
67
|
+
example "fails", :failed
|
68
|
+
example "is unimplemented", :pending, "implement me"
|
83
69
|
end
|
84
70
|
end
|
85
71
|
|
86
72
|
it "outputs example names and status" do
|
87
|
-
normalized_output.
|
73
|
+
expect(normalized_output).to eql(<<~EOF)
|
88
74
|
suite {
|
89
75
|
works OK (N.NNs)
|
90
|
-
is unimplemented PENDING: implement me (N.NNs)
|
91
76
|
fails FAILED (N.NNs)
|
77
|
+
is unimplemented PENDING: implement me (N.NNs)
|
78
|
+
} (N.NNs)
|
79
|
+
EOF
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
context "with nested example groups" do
|
85
|
+
|
86
|
+
before do
|
87
|
+
example_group "top" do
|
88
|
+
example_group "A" do
|
89
|
+
end
|
90
|
+
example_group "B" do
|
91
|
+
example_group "1" do
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "outputs nested group names" do
|
98
|
+
expect(normalized_output).to eql(<<~EOF)
|
99
|
+
top {
|
100
|
+
A (N.NNs)
|
101
|
+
B {
|
102
|
+
1 (N.NNs)
|
103
|
+
} (N.NNs)
|
92
104
|
} (N.NNs)
|
93
105
|
EOF
|
94
106
|
end
|
@@ -97,10 +109,9 @@ describe RSpec::Longrun::Formatter do
|
|
97
109
|
|
98
110
|
context "with steps" do
|
99
111
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
example "has steps" do
|
112
|
+
before do
|
113
|
+
example_group "suite" do
|
114
|
+
example "has steps", :passed do
|
104
115
|
step "Collect underpants" do
|
105
116
|
end
|
106
117
|
step "Er ..." do
|
@@ -113,14 +124,15 @@ describe RSpec::Longrun::Formatter do
|
|
113
124
|
end
|
114
125
|
|
115
126
|
it "outputs steps" do
|
116
|
-
normalized_output.
|
127
|
+
expect(normalized_output).to eql(<<~EOF)
|
117
128
|
suite {
|
118
129
|
has steps {
|
119
|
-
Collect underpants (N.NNs)
|
130
|
+
Collect underpants ✓ (N.NNs)
|
120
131
|
Er ... {
|
121
|
-
(thinking) (N.NNs)
|
122
|
-
} (N.NNs)
|
123
|
-
|
132
|
+
(thinking) ✓ (N.NNs)
|
133
|
+
} ✓ (N.NNs)
|
134
|
+
Profit! ✓ (N.NNs)
|
135
|
+
} OK (N.NNs)
|
124
136
|
} (N.NNs)
|
125
137
|
EOF
|
126
138
|
end
|
metadata
CHANGED
@@ -1,32 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-longrun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mike Williams
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-06-08 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec-core
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 3.7.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 3.7.0
|
30
27
|
description:
|
31
28
|
email:
|
32
29
|
- mdub@dogbiscuit.org
|
@@ -34,16 +31,18 @@ executables: []
|
|
34
31
|
extensions: []
|
35
32
|
extra_rdoc_files: []
|
36
33
|
files:
|
37
|
-
- .gitignore
|
38
|
-
- .rspec
|
39
|
-
- .travis.yml
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
40
37
|
- Gemfile
|
41
38
|
- LICENSE
|
42
39
|
- README.md
|
43
40
|
- Rakefile
|
44
41
|
- examples/example_spec.rb
|
42
|
+
- examples/nested_spec.rb
|
43
|
+
- examples/status_spec.rb
|
44
|
+
- examples/stepped_spec.rb
|
45
45
|
- lib/rspec/longrun.rb
|
46
|
-
- lib/rspec/longrun/core_ext.rb
|
47
46
|
- lib/rspec/longrun/dsl.rb
|
48
47
|
- lib/rspec/longrun/formatter.rb
|
49
48
|
- lib/rspec/longrun/version.rb
|
@@ -51,33 +50,26 @@ files:
|
|
51
50
|
- spec/rspec/longrun/formatter_spec.rb
|
52
51
|
homepage: http://github.com/mdub/rspec-longrun
|
53
52
|
licenses: []
|
53
|
+
metadata: {}
|
54
54
|
post_install_message:
|
55
55
|
rdoc_options: []
|
56
56
|
require_paths:
|
57
57
|
- lib
|
58
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
-
none: false
|
60
59
|
requirements:
|
61
|
-
- -
|
60
|
+
- - ">="
|
62
61
|
- !ruby/object:Gem::Version
|
63
62
|
version: '0'
|
64
|
-
segments:
|
65
|
-
- 0
|
66
|
-
hash: 1047382986774099312
|
67
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
64
|
requirements:
|
70
|
-
- -
|
65
|
+
- - ">="
|
71
66
|
- !ruby/object:Gem::Version
|
72
67
|
version: '0'
|
73
|
-
segments:
|
74
|
-
- 0
|
75
|
-
hash: 1047382986774099312
|
76
68
|
requirements: []
|
77
69
|
rubyforge_project:
|
78
|
-
rubygems_version:
|
70
|
+
rubygems_version: 2.7.6
|
79
71
|
signing_key:
|
80
|
-
specification_version:
|
72
|
+
specification_version: 4
|
81
73
|
summary: An RSpec formatter for long-running specs.
|
82
74
|
test_files:
|
83
75
|
- spec/rspec/longrun/formatter_spec.rb
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'rspec/core'
|
2
|
-
require 'rspec/core/formatters/base_formatter'
|
3
|
-
|
4
|
-
# extend rspec-core with support for "steps"
|
5
|
-
module RSpec::Core
|
6
|
-
|
7
|
-
class Reporter
|
8
|
-
|
9
|
-
if defined?(NOTIFICATIONS)
|
10
|
-
NOTIFICATIONS.push("step_started", "step_finished")
|
11
|
-
end
|
12
|
-
|
13
|
-
def step_started(description)
|
14
|
-
notify :step_started, description
|
15
|
-
end
|
16
|
-
|
17
|
-
def step_finished(description)
|
18
|
-
notify :step_finished, description
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
unless defined?(Reporter::NOTIFICATIONS)
|
24
|
-
|
25
|
-
class Formatters::BaseFormatter
|
26
|
-
|
27
|
-
def step_started(description)
|
28
|
-
end
|
29
|
-
|
30
|
-
def step_finished(description)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
class Example
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
alias :start_without_reporter :start
|
42
|
-
|
43
|
-
def start(reporter)
|
44
|
-
start_without_reporter(reporter)
|
45
|
-
@example_group_instance.instance_variable_set(:@_rspec_reporter, reporter)
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|