rspec-nc 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +3 -0
- data/Rakefile +3 -1
- data/lib/nc.rb +20 -5
- data/lib/nc_fail.rb +5 -0
- data/lib/nc_first_fail.rb +8 -1
- data/rspec-nc.gemspec +1 -1
- data/spec/nc_first_fail_spec.rb +67 -11
- data/spec/nc_spec.rb +47 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b1796d62f6c54875750b5e0be927291392b0d3a
|
4
|
+
data.tar.gz: 44a512f7a0a22131af968a1e478a5c35e8aa7217
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f78e9cbec54f20211bf9533e5958e1bb314046fd4d950d439675a6274d7a922ca160c1773a92bc311ff2151e110ec3d424efff6004404ac46eca2deea4daaced
|
7
|
+
data.tar.gz: 734c11e4e6352af74e1be6fdf2402ee7e163a9c56f00bf4fc011d905e2f374a9be98a5806120170f8af4801c2cf7875d6813ffef096b822566a5f8f1a97ec6ab
|
data/README.markdown
CHANGED
data/Rakefile
CHANGED
data/lib/nc.rb
CHANGED
@@ -2,11 +2,26 @@ require 'rspec/core/formatters/base_text_formatter'
|
|
2
2
|
require 'terminal-notifier'
|
3
3
|
|
4
4
|
class Nc < RSpec::Core::Formatters::BaseTextFormatter
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
def self.rspec_3?
|
7
|
+
RSpec::Core::Version::STRING.split('.').first == "3"
|
8
|
+
end
|
9
|
+
|
10
|
+
if rspec_3?
|
11
|
+
RSpec::Core::Formatters.register self, :dump_summary
|
7
12
|
end
|
8
13
|
|
9
|
-
def dump_summary(
|
14
|
+
def dump_summary(*args)
|
15
|
+
if self.class.rspec_3?
|
16
|
+
notification = args[0]
|
17
|
+
duration = notification.duration
|
18
|
+
example_count = notification.example_count
|
19
|
+
failure_count = notification.failure_count
|
20
|
+
pending_count = notification.pending_count
|
21
|
+
else
|
22
|
+
duration, example_count, failure_count, pending_count = args
|
23
|
+
end
|
24
|
+
|
10
25
|
body = []
|
11
26
|
body << "Finished in #{_format_duration duration}"
|
12
27
|
body << _summary_line(example_count, failure_count, pending_count)
|
@@ -22,8 +37,8 @@ class Nc < RSpec::Core::Formatters::BaseTextFormatter
|
|
22
37
|
say title, body.join("\n")
|
23
38
|
end
|
24
39
|
|
25
|
-
def dump_pending; end
|
26
|
-
def dump_failures; end
|
40
|
+
def dump_pending(*args); end
|
41
|
+
def dump_failures(*args); end
|
27
42
|
def message(message); end
|
28
43
|
|
29
44
|
private
|
data/lib/nc_fail.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'nc'
|
2
2
|
|
3
3
|
class NcFail < Nc
|
4
|
+
if rspec_3?
|
5
|
+
RSpec::Core::Formatters.register self, :example_failed
|
6
|
+
end
|
7
|
+
|
4
8
|
def say(title, body)
|
5
9
|
@failed_examples ||= []
|
6
10
|
return if @failed_examples.size <= 0
|
@@ -8,6 +12,7 @@ class NcFail < Nc
|
|
8
12
|
end
|
9
13
|
|
10
14
|
def example_failed(failure)
|
15
|
+
@failed_examples ||= []
|
11
16
|
@failed_examples << failure
|
12
17
|
end
|
13
18
|
end
|
data/lib/nc_first_fail.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
require 'nc'
|
2
2
|
|
3
3
|
class NcFirstFail < Nc
|
4
|
+
if rspec_3?
|
5
|
+
RSpec::Core::Formatters.register self, :example_failed
|
6
|
+
end
|
7
|
+
|
4
8
|
def example_failed(example)
|
9
|
+
# For rspec3
|
10
|
+
example = example.example if example.respond_to?(:example)
|
5
11
|
@failed_examples ||= []
|
6
12
|
if @failed_examples.size == 0
|
7
13
|
name = File.basename(File.expand_path '.')
|
@@ -10,7 +16,8 @@ class NcFirstFail < Nc
|
|
10
16
|
@failed_examples << example
|
11
17
|
end
|
12
18
|
|
13
|
-
def dump_summary(
|
19
|
+
def dump_summary(*args)
|
20
|
+
failure_count = self.class.rspec_3? ? args[0].failure_count : args[2]
|
14
21
|
super if failure_count == 0
|
15
22
|
end
|
16
23
|
end
|
data/rspec-nc.gemspec
CHANGED
data/spec/nc_first_fail_spec.rb
CHANGED
@@ -7,24 +7,80 @@ describe NcFirstFail do
|
|
7
7
|
let(:example2) { double 'example2' }
|
8
8
|
|
9
9
|
let(:failure) { "\u26D4" }
|
10
|
+
let(:success) { "\u2705" }
|
10
11
|
let(:exception) { 'exception' }
|
11
12
|
let(:description) { 'description' }
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
context 'with RSpec 2' do
|
15
|
+
before do
|
16
|
+
allow(formatter.class).to receive(:rspec_3?).and_return(false)
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
:
|
19
|
-
|
19
|
+
it 'notifies the first failure only' do
|
20
|
+
allow(example).to receive(:metadata).and_return({:full_description => description})
|
21
|
+
allow(example).to receive(:exception).and_return(exception)
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
expect(TerminalNotifier).to receive(:notify).with("#{description}\n#{exception}",
|
24
|
+
:title => "#{failure} #{current_dir}: Failure"
|
25
|
+
).once
|
26
|
+
|
27
|
+
formatter.example_failed(example)
|
28
|
+
formatter.example_failed(example2)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "doesn't notify in the end if there has been any failures" do
|
32
|
+
expect(TerminalNotifier).to_not receive(:notify)
|
33
|
+
|
34
|
+
formatter.dump_summary(0.0001, 2, 1, 0)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'notifies in the end if there is no failures' do
|
38
|
+
expect(TerminalNotifier).to receive(:notify).with(
|
39
|
+
"Finished in 0.0001 seconds\n2 examples, 0 failures",
|
40
|
+
:title => "#{success} #{current_dir}: Success"
|
41
|
+
)
|
42
|
+
|
43
|
+
formatter.dump_summary(0.0001, 2, 0, 0)
|
44
|
+
end
|
23
45
|
end
|
24
46
|
|
25
|
-
|
26
|
-
|
47
|
+
context 'with RSpec 3' do
|
48
|
+
let(:notification) do
|
49
|
+
Struct.new(:duration, :example_count, :failure_count, :pending_count).new(0.0001, 3, 1, 1)
|
50
|
+
end
|
51
|
+
let(:success_notification) do
|
52
|
+
Struct.new(:duration, :example_count, :failure_count, :pending_count).new(0.0001, 2, 0, 0)
|
53
|
+
end
|
54
|
+
|
55
|
+
before do
|
56
|
+
allow(formatter.class).to receive(:rspec_3?).and_return(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'notifies the first failure only' do
|
60
|
+
allow(example).to receive(:metadata).and_return({:full_description => description})
|
61
|
+
allow(example).to receive(:exception).and_return(exception)
|
62
|
+
|
63
|
+
expect(TerminalNotifier).to receive(:notify).with("#{description}\n#{exception}",
|
64
|
+
:title => "#{failure} #{current_dir}: Failure"
|
65
|
+
).once
|
66
|
+
|
67
|
+
formatter.example_failed(double(example: example))
|
68
|
+
formatter.example_failed(double(example: example2))
|
69
|
+
end
|
70
|
+
|
71
|
+
it "doesn't notify in the end if there has been any failures" do
|
72
|
+
expect(TerminalNotifier).to_not receive(:notify)
|
73
|
+
|
74
|
+
formatter.dump_summary(notification)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'notifies in the end if there is no failures' do
|
78
|
+
expect(TerminalNotifier).to receive(:notify).with(
|
79
|
+
"Finished in 0.0001 seconds\n2 examples, 0 failures",
|
80
|
+
:title => "#{success} #{current_dir}: Success"
|
81
|
+
)
|
27
82
|
|
28
|
-
|
83
|
+
formatter.dump_summary(success_notification)
|
84
|
+
end
|
29
85
|
end
|
30
86
|
end
|
data/spec/nc_spec.rb
CHANGED
@@ -8,30 +8,54 @@ describe Nc do
|
|
8
8
|
let(:success) { "\u2705" }
|
9
9
|
let(:failure) { "\u26D4" }
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
context 'with RSpec 2' do
|
12
|
+
before do
|
13
|
+
allow(formatter.class).to receive(:rspec_3?).and_return(false)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns the summary' do
|
17
|
+
expect(TerminalNotifier).to receive(:notify).with(
|
18
|
+
"Finished in 0.0001 seconds\n3 examples, 1 failure, 1 pending",
|
19
|
+
:title => "#{failure} #{current_dir}: 1 failed example"
|
20
|
+
)
|
21
|
+
|
22
|
+
formatter.dump_summary(0.0001, 3, 1, 1)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns a failing notification' do
|
26
|
+
expect(TerminalNotifier).to receive(:notify).with(
|
27
|
+
"Finished in 0.0001 seconds\n1 example, 1 failure",
|
28
|
+
:title => "#{failure} #{current_dir}: 1 failed example"
|
29
|
+
)
|
30
|
+
|
31
|
+
formatter.dump_summary(0.0001, 1, 1, 0)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns a success notification' do
|
35
|
+
expect(TerminalNotifier).to receive(:notify).with(
|
36
|
+
"Finished in 0.0001 seconds\n1 example, 0 failures",
|
37
|
+
:title => "#{success} #{current_dir}: Success"
|
38
|
+
)
|
39
|
+
|
40
|
+
formatter.dump_summary(0.0001, 1, 0, 0)
|
41
|
+
end
|
18
42
|
end
|
19
43
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
44
|
+
context 'with RSpec 3' do
|
45
|
+
let(:notification) {
|
46
|
+
Struct.new(:duration, :example_count, :failure_count, :pending_count).new(0.0001, 3, 1, 1)
|
47
|
+
}
|
48
|
+
before do
|
49
|
+
allow(formatter.class).to receive(:rspec_3?).and_return(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'shows the summary' do
|
53
|
+
expect(TerminalNotifier).to receive(:notify).with(
|
54
|
+
"Finished in 0.0001 seconds\n3 examples, 1 failure, 1 pending",
|
55
|
+
:title => "#{failure} #{current_dir}: 1 failed example"
|
56
|
+
)
|
57
|
+
|
58
|
+
formatter.dump_summary(notification)
|
59
|
+
end
|
36
60
|
end
|
37
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-nc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Odin Dutton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terminal-notifier
|