rspec-nc 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2b8f93c83bbd95fcf6ee2f1733e04b4d1d16ef3
4
- data.tar.gz: 0cd2bc1e3dfaea772e799a6ed05c1b1d4922d9d4
3
+ metadata.gz: 9f17893a6ec6eca20680fc2d7e19449276eb95d8
4
+ data.tar.gz: e3d9ee891412465623cc782c8c6e3b976af5ba26
5
5
  SHA512:
6
- metadata.gz: b1ab0cffb3b17e0067df6414cd75f066492f72a05e6f44b26eda48a7edffdf1c07e3460aecd506b027e9a0f66b422f42bffacd5747ea6c2e993c4ab41173b0cf
7
- data.tar.gz: da5a61732c2c259d1b983f648837ab615159f9e1b9ac7f78b8bb8c7f83559588f1463adc9149a580f6ac3d06ec915f9b28f1bccbac0982002585a57b29c2ea4c
6
+ metadata.gz: 0c883b6b56523daa87605815575282e953384f8b7e066d8ed93c4fab507caf31bfb9d7a7305210f8e3c0e892d889fe78e92d0ae7ff6d67fda87daf4a226b32de
7
+ data.tar.gz: 2e2a2781669641e82219f60663658e38dff1caf58f328c636f6cb1f6de24ae8f3073b1d59813ef9565027296ffbb78c495aa71b8a71f398c54b464cebd55fa50
@@ -1,4 +1 @@
1
- gemfile:
2
- - gemfiles/rspec29.gemfile
3
- - gemfiles/rspec3.gemfile
4
1
  script: 'bundle exec rake spec'
data/lib/nc.rb CHANGED
@@ -1,73 +1,25 @@
1
- require 'rspec/core/formatters/base_text_formatter'
1
+ require 'rspec/core/formatters/base_formatter'
2
2
  require 'terminal-notifier'
3
3
 
4
- class Nc < RSpec::Core::Formatters::BaseTextFormatter
5
- def self.rspec_3?
6
- RSpec::Core::Version::STRING.split('.').first == "3"
7
- end
4
+ class Nc < RSpec::Core::Formatters::BaseFormatter
5
+ SUCCESS_EMOJI = "\u2705"
6
+ FAILURE_EMOJI = "\u26D4"
8
7
 
9
- if rspec_3?
10
- RSpec::Core::Formatters.register self, :dump_summary
11
- end
8
+ RSpec::Core::Formatters.register self, :dump_summary
12
9
 
13
- def dump_summary(*args)
14
- if self.class.rspec_3?
15
- notification = args[0]
16
- duration = notification.duration
17
- example_count = notification.example_count
18
- failure_count = notification.failure_count
19
- pending_count = notification.pending_count
10
+ def dump_summary(notification)
11
+ body = "Finished in #{notification.formatted_duration}\n#{notification.totals_line}"
12
+ title = if notification.failure_count > 0
13
+ "#{FAILURE_EMOJI} #{directory_name}: #{notification.failure_count} failed example#{notification.failure_count == 1 ? nil : 's'}"
20
14
  else
21
- duration, example_count, failure_count, pending_count = args
15
+ "#{SUCCESS_EMOJI} #{directory_name}: Success"
22
16
  end
23
-
24
- body = []
25
- body << "Finished in #{_format_duration duration}"
26
- body << _summary_line(example_count, failure_count, pending_count)
27
-
28
- name = File.basename(File.expand_path '.')
29
-
30
- title = if failure_count > 0
31
- "\u26D4 #{name}: #{failure_count} failed example#{failure_count == 1 ? nil : 's'}"
32
- else
33
- "\u2705 #{name}: Success"
34
- end
35
-
36
- say title, body.join("\n")
17
+ TerminalNotifier.notify body, title: title
37
18
  end
38
19
 
39
- def dump_pending(*args); end
40
- def dump_failures(*args); end
41
- def message(message); end
42
-
43
20
  private
44
21
 
45
- def say(title, body)
46
- TerminalNotifier.notify body, :title => title
22
+ def directory_name
23
+ File.basename File.expand_path '.'
47
24
  end
48
-
49
- def _format_duration(duration)
50
- if respond_to? :format_duration
51
- format_duration duration
52
- else
53
- require 'rspec/core/formatters/helpers' unless Object.const_defined?('RSpec')
54
- RSpec::Core::Formatters::Helpers.format_duration duration
55
- end
56
- end
57
-
58
- def _summary_line(example_count, failure_count, pending_count)
59
- if respond_to? :summary_line
60
- summary_line(example_count, failure_count, pending_count)
61
- else
62
- RSpec::Core::Notifications::SummaryNotification.new(
63
- nil,
64
- SizeResponder.new(example_count),
65
- SizeResponder.new(failure_count),
66
- SizeResponder.new(pending_count),
67
- nil
68
- ).totals_line
69
- end
70
- end
71
-
72
- SizeResponder = Struct.new(:size)
73
25
  end
@@ -1,18 +1,11 @@
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
-
8
- def say(title, body)
9
- @failed_examples ||= []
10
- return if @failed_examples.size <= 0
11
- super
12
- end
4
+ RSpec::Core::Formatters.register self, :dump_summary
13
5
 
14
- def example_failed(failure)
15
- @failed_examples ||= []
16
- @failed_examples << failure
6
+ def dump_summary(notification)
7
+ if notification.failure_count > 0
8
+ super
9
+ end
17
10
  end
18
11
  end
@@ -1,23 +1,21 @@
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
4
+ RSpec::Core::Formatters.register self, :example_failed
7
5
 
8
- def example_failed(example)
9
- # For rspec3
10
- example = example.example if example.respond_to?(:example)
11
- @failed_examples ||= []
12
- if @failed_examples.size == 0
13
- name = File.basename(File.expand_path '.')
14
- say "\u26D4 #{name}: Failure", "#{example.metadata[:full_description]}\n#{example.exception}"
6
+ def example_failed(notification)
7
+ example = notification.example
8
+ body = "#{example.metadata[:full_description]}\n#{example.exception}"
9
+ title = "#{FAILURE_EMOJI} #{directory_name}: Failure"
10
+ unless @failed
11
+ TerminalNotifier.notify body, title: title
15
12
  end
16
- @failed_examples << example
13
+ @failed = true
17
14
  end
18
15
 
19
- def dump_summary(*args)
20
- failure_count = self.class.rspec_3? ? args[0].failure_count : args[2]
21
- super if failure_count == 0
16
+ def dump_summary(notification)
17
+ if notification.failure_count == 0
18
+ super
19
+ end
22
20
  end
23
21
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = 'rspec-nc'
4
- gem.version = '0.2.1'
4
+ gem.version = '0.3.0'
5
5
  gem.authors = ['Odin Dutton']
6
6
  gem.email = ['odindutton@gmail.com']
7
7
  gem.description = 'https://github.com/twe4ked/rspec-nc'
@@ -10,10 +10,11 @@ Gem::Specification.new do |gem|
10
10
  gem.license = 'MIT'
11
11
 
12
12
  gem.add_dependency 'terminal-notifier', '>= 1.4'
13
- gem.add_dependency 'rspec', '>= 2.9'
13
+ gem.add_dependency 'rspec', '>= 3'
14
14
 
15
15
  gem.add_development_dependency 'rake'
16
16
  gem.add_development_dependency 'wwtd'
17
+ gem.add_development_dependency 'pry'
17
18
 
18
19
  gem.files = `git ls-files`.split($\)
19
20
  gem.test_files = gem.files.grep(%r{^(spec)/})
@@ -2,17 +2,29 @@ require 'nc_fail'
2
2
 
3
3
  describe NcFail do
4
4
  let(:formatter) { NcFail.new(StringIO.new) }
5
+ let(:notification) do
6
+ instance_double(RSpec::Core::Notifications::SummaryNotification,
7
+ formatted_duration: double,
8
+ totals_line: double,
9
+ failure_count: failure_count,
10
+ )
11
+ end
5
12
 
6
- it 'returns a failing notification' do
7
- expect(TerminalNotifier).to receive(:notify)
13
+ context 'with failing examples' do
14
+ let(:failure_count) { 1 }
8
15
 
9
- formatter.instance_variable_set('@failed_examples', [1])
10
- formatter.say('title', 'body')
16
+ it 'sends a failure summary notification' do
17
+ expect(TerminalNotifier).to receive(:notify)
18
+ formatter.dump_summary(notification)
19
+ end
11
20
  end
12
21
 
13
- it 'does not return a success notification when tests are passing' do
14
- expect(TerminalNotifier).to_not receive(:notify)
22
+ context 'with all examples passing' do
23
+ let(:failure_count) { 0 }
15
24
 
16
- formatter.say('title', 'body')
25
+ it 'does not send a notification' do
26
+ expect(TerminalNotifier).to_not receive(:notify)
27
+ formatter.dump_summary(notification)
28
+ end
17
29
  end
18
30
  end
@@ -1,86 +1,45 @@
1
1
  require 'nc_first_fail'
2
2
 
3
3
  describe NcFirstFail do
4
- let(:formatter) { NcFirstFail.new(StringIO.new) }
4
+ let(:formatter) { NcFirstFail.new(StringIO.new) }
5
5
  let(:current_dir) { File.basename(File.expand_path '.') }
6
- let(:example) { double 'example' }
7
- let(:example2) { double 'example2' }
8
-
9
- let(:failure) { "\u26D4" }
10
- let(:success) { "\u2705" }
11
- let(:exception) { 'exception' }
12
- let(:description) { 'description' }
13
-
14
- context 'with RSpec 2' do
15
- before do
16
- allow(formatter.class).to receive(:rspec_3?).and_return(false)
17
- end
18
-
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)
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
6
+ let(:failure_count) { 1 }
7
+ let(:summary_notification) do
8
+ instance_double(RSpec::Core::Notifications::SummaryNotification,
9
+ formatted_duration: '0.0001 seconds',
10
+ totals_line: '3 examples, 1 failure, 1 pending',
11
+ failure_count: failure_count,
12
+ )
13
+ end
14
+ let(:failed_example_notification) do
15
+ instance_double(RSpec::Core::Notifications::FailedExampleNotification,
16
+ example: double(:example,
17
+ metadata: {full_description: '_full_description_'},
18
+ exception: '_exception_',
19
+ ),
20
+ )
45
21
  end
46
22
 
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
23
+ it 'sends a failure notification for the first failure only' do
24
+ expect(TerminalNotifier).to receive(:notify).with(
25
+ "_full_description_\n_exception_",
26
+ title: "#{Nc::FAILURE_EMOJI} #{current_dir}: Failure",
27
+ )
28
+ formatter.example_failed failed_example_notification
66
29
 
67
- formatter.example_failed(double(example: example))
68
- formatter.example_failed(double(example: example2))
69
- end
30
+ expect(TerminalNotifier).to_not receive(:notify)
31
+ formatter.example_failed failed_example_notification
70
32
 
71
- it "doesn't notify in the end if there has been any failures" do
72
- expect(TerminalNotifier).to_not receive(:notify)
33
+ expect(TerminalNotifier).to_not receive(:notify)
34
+ formatter.dump_summary summary_notification
35
+ end
73
36
 
74
- formatter.dump_summary(notification)
75
- end
76
37
 
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
- )
38
+ context 'with all examples passing' do
39
+ let(:failure_count) { 0 }
82
40
 
83
- formatter.dump_summary(success_notification)
41
+ it 'sends a success summary notification' do
42
+ formatter.dump_summary summary_notification
84
43
  end
85
44
  end
86
45
  end
@@ -1,60 +1,41 @@
1
1
  require 'nc'
2
2
 
3
- describe Nc do
4
- let(:formatter) { Nc.new(StringIO.new) }
3
+ RSpec.describe Nc do
4
+ let(:formatter) { Nc.new(StringIO.new) }
5
5
  let(:current_dir) { File.basename(File.expand_path '.') }
6
6
 
7
- # emoji
8
- let(:success) { "\u2705" }
9
- let(:failure) { "\u26D4" }
10
-
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"
7
+ context 'with failing examples' do
8
+ let(:notification) do
9
+ instance_double(RSpec::Core::Notifications::SummaryNotification,
10
+ formatted_duration: '0.0001 seconds',
11
+ totals_line: '3 examples, 1 failure, 1 pending',
12
+ failure_count: 1,
20
13
  )
21
-
22
- formatter.dump_summary(0.0001, 3, 1, 1)
23
14
  end
24
15
 
25
- it 'returns a failing notification' do
16
+ it 'sends a failure summary notification' do
26
17
  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"
18
+ "Finished in 0.0001 seconds\n3 examples, 1 failure, 1 pending",
19
+ :title => "#{Nc::FAILURE_EMOJI} #{current_dir}: 1 failed example"
38
20
  )
39
-
40
- formatter.dump_summary(0.0001, 1, 0, 0)
21
+ formatter.dump_summary(notification)
41
22
  end
42
23
  end
43
24
 
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)
25
+ context 'with all examples passing' do
26
+ let(:notification) do
27
+ instance_double(RSpec::Core::Notifications::SummaryNotification,
28
+ formatted_duration: '0.0001 seconds',
29
+ totals_line: '3 examples, 0 failures, 1 pending',
30
+ failure_count: 0,
31
+ )
50
32
  end
51
33
 
52
- it 'shows the summary' do
34
+ it 'sends a success summary notification' do
53
35
  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"
36
+ "Finished in 0.0001 seconds\n3 examples, 0 failures, 1 pending",
37
+ :title => "#{Nc::SUCCESS_EMOJI} #{current_dir}: Success"
56
38
  )
57
-
58
39
  formatter.dump_summary(notification)
59
40
  end
60
41
  end
@@ -0,0 +1,21 @@
1
+ # This test isn't part of the actual suite it's to manually test the formatters.
2
+ require 'nc'
3
+
4
+ RSpec.describe 'to test the gem' do
5
+ it 'passes' do
6
+ expect(0).to eq 0
7
+ end
8
+
9
+ it 'fails' do
10
+ expect(1).to eq 2
11
+ end
12
+
13
+ it 'fails again' do
14
+ expect(3).to eq 4
15
+ end
16
+
17
+ it 'pending' do
18
+ pending 'for a reason'
19
+ expect(5).to eq 6
20
+ end
21
+ 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.2.1
4
+ version: 0.3.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: 2015-10-29 00:00:00.000000000 Z
11
+ date: 2016-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: terminal-notifier
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '2.9'
33
+ version: '3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '2.9'
40
+ version: '3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: https://github.com/twe4ked/rspec-nc
70
84
  email:
71
85
  - odindutton@gmail.com
@@ -79,8 +93,6 @@ files:
79
93
  - LICENSE
80
94
  - README.markdown
81
95
  - Rakefile
82
- - gemfiles/rspec29.gemfile
83
- - gemfiles/rspec3.gemfile
84
96
  - lib/nc.rb
85
97
  - lib/nc_fail.rb
86
98
  - lib/nc_first_fail.rb
@@ -88,6 +100,7 @@ files:
88
100
  - spec/nc_fail_spec.rb
89
101
  - spec/nc_first_fail_spec.rb
90
102
  - spec/nc_spec.rb
103
+ - spec/test.rb
91
104
  homepage: https://github.com/twe4ked/rspec-nc
92
105
  licenses:
93
106
  - MIT
@@ -116,3 +129,4 @@ test_files:
116
129
  - spec/nc_fail_spec.rb
117
130
  - spec/nc_first_fail_spec.rb
118
131
  - spec/nc_spec.rb
132
+ - spec/test.rb
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'rake'
4
- gem 'wwtd'
5
-
6
- gem 'terminal-notifier', '>= 1.4'
7
- gem 'rspec', '~> 2.9'
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'rake'
4
- gem 'wwtd'
5
-
6
- gem 'terminal-notifier', '>= 1.4'
7
- gem 'rspec', '~> 3.0'