rspec-by 0.0.5
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.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +1 -0
- data/lib/rspec/by/core_ext.rb +53 -0
- data/lib/rspec/by/formatter.rb +96 -0
- data/lib/rspec/by/version.rb +5 -0
- data/lib/rspec/by.rb +2 -0
- data/rspec-by.gemspec +18 -0
- data/spec/rspec/by/formatter_spec.rb +106 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 530feafb2ba4d8e165d3a81eb827ec803ac4094c
|
4
|
+
data.tar.gz: 31148428b190d923d725d1ac6204c4060da170e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf740d5e8e9ea7e20330d41a18ed725fb61fe4d7a2a969125e56369963b8284db431f5b2fa2d56134ebe72abd776ade1756d225a17ac39b85d531aea57014914
|
7
|
+
data.tar.gz: b4cbe3c83717f535e208be70751d6b03d26dda461d1ba1ea2c47fd8f02a742ec48db015c2379bc882e7817d38222be99a08c3c6c81b1b485ff8a5dd27eb83aa2
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalization:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-r rspec/by -f RSpec::By::Formatter --colour
|
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 @@
|
|
1
|
+
An RSpec formatter that provides nice message outputs akin to cucumber steps.
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "rspec/core"
|
2
|
+
require "rspec/core/formatters/documentation_formatter"
|
3
|
+
|
4
|
+
# monkey patching rspec
|
5
|
+
module RSpec::Core
|
6
|
+
class Reporter
|
7
|
+
if defined?(NOTIFICATIONS)
|
8
|
+
NOTIFICATIONS.push("by_started", "by_finished")
|
9
|
+
end
|
10
|
+
|
11
|
+
def by_started(message)
|
12
|
+
notify :by_started, message
|
13
|
+
end
|
14
|
+
|
15
|
+
def by_ended(message = '')
|
16
|
+
notify :by_ended, message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
unless defined?(Reporter::NOTIFICATIONS)
|
21
|
+
class Formatters::DocumentationFormatter
|
22
|
+
def by_started(message)
|
23
|
+
end
|
24
|
+
def by_ended(message = '')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class ExampleGroup
|
30
|
+
def by message, level=0
|
31
|
+
pending(message) unless block_given?
|
32
|
+
begin
|
33
|
+
@by_reporter.by_started(message)
|
34
|
+
yield
|
35
|
+
ensure
|
36
|
+
@by_reporter.by_ended
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
alias and_by by
|
41
|
+
end
|
42
|
+
|
43
|
+
class Example
|
44
|
+
private
|
45
|
+
|
46
|
+
alias :start_without_reporter :start
|
47
|
+
|
48
|
+
def start(reporter)
|
49
|
+
start_without_reporter(reporter)
|
50
|
+
@example_group_instance.instance_variable_set(:@by_reporter, reporter)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "rspec/core/formatters/documentation_formatter"
|
2
|
+
|
3
|
+
##
|
4
|
+
# This class formats RSpec to puts failing tests instantly with some
|
5
|
+
# nice outputting/benchmarking. Useful for longer suites.
|
6
|
+
# Known issue: when by statements are nested, the output gets muddled
|
7
|
+
|
8
|
+
module RSpec
|
9
|
+
module By
|
10
|
+
class Formatter < RSpec::Core::Formatters::DocumentationFormatter
|
11
|
+
RSpec::Core::Formatters.register self,
|
12
|
+
:example_failed,
|
13
|
+
:example_started,
|
14
|
+
:example_passed,
|
15
|
+
:by_started,
|
16
|
+
:by_ended
|
17
|
+
|
18
|
+
RIGHT_MARGIN = 80
|
19
|
+
|
20
|
+
def initialize(output)
|
21
|
+
super(output)
|
22
|
+
@failed_examples = []
|
23
|
+
@by_message_length = 0
|
24
|
+
end
|
25
|
+
|
26
|
+
def example_started(notification)
|
27
|
+
output.puts(
|
28
|
+
"#{current_indentation}Example: #{notification.example.description}")
|
29
|
+
@group_level += 1
|
30
|
+
@example_began = @during = RSpec::Core::Time.now
|
31
|
+
end
|
32
|
+
|
33
|
+
def example_passed(passed)
|
34
|
+
@group_level -= 1
|
35
|
+
passed_msg = indent("Passed")
|
36
|
+
end_msg = end_tm.rjust(RIGHT_MARGIN - passed_msg.length, ' ')
|
37
|
+
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
|
38
|
+
"#{passed_msg}#{end_msg}", :success)
|
39
|
+
end
|
40
|
+
|
41
|
+
def example_failed(failure)
|
42
|
+
@group_level -= 1
|
43
|
+
output.puts("#{current_indentation}Failed in #{end_tm}")
|
44
|
+
@failed_examples << failure.example
|
45
|
+
output.puts failure.fully_formatted(@failed_examples.size)
|
46
|
+
output.puts
|
47
|
+
end
|
48
|
+
|
49
|
+
def by_started message
|
50
|
+
res = indent message
|
51
|
+
@by_message_length = res.length
|
52
|
+
output.print by_output(res)
|
53
|
+
end
|
54
|
+
|
55
|
+
def by_ended(message)
|
56
|
+
message += during_tm
|
57
|
+
output.puts by_output(message.rjust(RIGHT_MARGIN - @by_message_length, ' '))
|
58
|
+
end
|
59
|
+
|
60
|
+
def indent message
|
61
|
+
"#{current_indentation}#{message}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def by_output message
|
65
|
+
RSpec::Core::Formatters::ConsoleCodes.wrap(message, :cyan)
|
66
|
+
end
|
67
|
+
|
68
|
+
def during_tm
|
69
|
+
temp = RSpec::Core::Time.now
|
70
|
+
delta = temp - @during
|
71
|
+
@during = temp
|
72
|
+
format_time(delta)
|
73
|
+
end
|
74
|
+
|
75
|
+
def end_tm
|
76
|
+
delta = RSpec::Core::Time.now - @example_began
|
77
|
+
format_time(delta)
|
78
|
+
end
|
79
|
+
|
80
|
+
def format_time(duration)
|
81
|
+
if duration > 60
|
82
|
+
minutes = duration.to_i / 60
|
83
|
+
seconds = duration - minutes * 60
|
84
|
+
"#{minutes}m #{format_seconds(seconds)}s"
|
85
|
+
else
|
86
|
+
"#{format_seconds(duration)}s"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def format_seconds(float, precision = nil)
|
91
|
+
precision ||= (float < 1) ? 5 : 2
|
92
|
+
sprintf("%.#{precision}f", float)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/rspec/by.rb
ADDED
data/rspec-by.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path("../lib/rspec/by/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'rspec-by'
|
5
|
+
s.version = RSpec::By::VERSION
|
6
|
+
s.date = '2016-03-30'
|
7
|
+
s.summary = "RSpec formatter"
|
8
|
+
s.description = "An RSpec formatter that provides step-like message output"
|
9
|
+
s.authors = ["Masaki Matsuo"]
|
10
|
+
s.email = 'masaki.matsuo@pnmac.com'
|
11
|
+
s.files = `git ls-files`.split($\)
|
12
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
13
|
+
s.require_paths = ["lib"]
|
14
|
+
s.homepage = 'https://github.com/sleepn247/rspec-by'
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.add_runtime_dependency("rspec-core", ">= 3")
|
18
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require "rspec/by/core_ext"
|
2
|
+
require "stringio"
|
3
|
+
|
4
|
+
module RSpec::By
|
5
|
+
RSpec.describe Formatter do
|
6
|
+
|
7
|
+
def undent(raw)
|
8
|
+
if raw =~ /\A( +)/
|
9
|
+
indent = $1
|
10
|
+
raw.gsub(/^#{indent}/, '').gsub(/ +$/, '')
|
11
|
+
else
|
12
|
+
raw
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def normalize_durations(output)
|
17
|
+
output.gsub(/(\d?m )?\d+\.\d+s/) do |dur|
|
18
|
+
$1 == 'm' ? "nm n.nns" : "n.nnnnns"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove_color(output)
|
23
|
+
output.gsub(/\e\[(\d+)(;\d+)*m/, '')
|
24
|
+
end
|
25
|
+
|
26
|
+
def reporter
|
27
|
+
@reporter ||= setup_reporter
|
28
|
+
end
|
29
|
+
|
30
|
+
def setup_reporter(*streams)
|
31
|
+
config.add_formatter described_class, *streams
|
32
|
+
@formatter = config.formatters.first
|
33
|
+
@reporter = config.reporter
|
34
|
+
end
|
35
|
+
|
36
|
+
def config
|
37
|
+
@configuration ||=
|
38
|
+
begin
|
39
|
+
config = RSpec::Core::Configuration.new
|
40
|
+
config.output_stream = formatter_output
|
41
|
+
config
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def formatter_output
|
46
|
+
@formatter_output ||= StringIO.new
|
47
|
+
end
|
48
|
+
|
49
|
+
def formatter
|
50
|
+
@formatter ||=
|
51
|
+
begin
|
52
|
+
setup_reporter
|
53
|
+
@formatter
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "outputs correctly" do
|
58
|
+
group = RSpec.describe("root")
|
59
|
+
context1 = group.describe("context 1")
|
60
|
+
context1.example("nested example 1.1"){}
|
61
|
+
context1.example("nested example 1.2") do
|
62
|
+
by('knock knock') {}
|
63
|
+
and_by("who's there?") {}
|
64
|
+
and_by('by') {}
|
65
|
+
and_by('by who?') {}
|
66
|
+
and_by('by by') {}
|
67
|
+
end
|
68
|
+
|
69
|
+
context11 = context1.describe("context 1.1")
|
70
|
+
context11.example("nested example 1.1.1"){}
|
71
|
+
context11.example("nested example 1.1.2"){}
|
72
|
+
|
73
|
+
context2 = group.describe("context 2")
|
74
|
+
context2.example("nested example 2.1"){}
|
75
|
+
context2.example("nested example 2.2"){}
|
76
|
+
|
77
|
+
group.run(reporter)
|
78
|
+
|
79
|
+
output = normalize_durations(formatter_output.string)
|
80
|
+
output = remove_color(output)
|
81
|
+
expect(output).to eq(normalize_durations("
|
82
|
+
root
|
83
|
+
context 1
|
84
|
+
Example: nested example 1.1
|
85
|
+
Passed 0.00022s
|
86
|
+
Example: nested example 1.2
|
87
|
+
knock knock 0.00022s
|
88
|
+
who's there? 0.00022s
|
89
|
+
by 0.00022s
|
90
|
+
by who? 0.00022s
|
91
|
+
by by 0.00022s
|
92
|
+
Passed 0.00022s
|
93
|
+
context 1.1
|
94
|
+
Example: nested example 1.1.1
|
95
|
+
Passed 0.00022s
|
96
|
+
Example: nested example 1.1.2
|
97
|
+
Passed 0.00022s
|
98
|
+
context 2
|
99
|
+
Example: nested example 2.1
|
100
|
+
Passed 0.00022s
|
101
|
+
Example: nested example 2.2
|
102
|
+
Passed 0.00022s
|
103
|
+
"))
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-by
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masaki Matsuo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
description: An RSpec formatter that provides step-like message output
|
28
|
+
email: masaki.matsuo@pnmac.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- ".rspec"
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- lib/rspec/by.rb
|
39
|
+
- lib/rspec/by/core_ext.rb
|
40
|
+
- lib/rspec/by/formatter.rb
|
41
|
+
- lib/rspec/by/version.rb
|
42
|
+
- rspec-by.gemspec
|
43
|
+
- spec/rspec/by/formatter_spec.rb
|
44
|
+
homepage: https://github.com/sleepn247/rspec-by
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.6.2
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: RSpec formatter
|
68
|
+
test_files:
|
69
|
+
- spec/rspec/by/formatter_spec.rb
|