rspec-nc 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1896186f478c686492227612152565cef066a07e
4
- data.tar.gz: 56f02cf23432812b5603db870b2561481c1e555d
3
+ metadata.gz: 0b1796d62f6c54875750b5e0be927291392b0d3a
4
+ data.tar.gz: 44a512f7a0a22131af968a1e478a5c35e8aa7217
5
5
  SHA512:
6
- metadata.gz: 63698aadc280f99e04cd6c0e1e8b844362e766f399bef0ce8212c0420393f215d774d8f55664cab2b337594fcd08dea194ad5a4a972a0d5c8e09ef5edf9b27cc
7
- data.tar.gz: c2308686aec0c280510bc39e0fa137fafd6873a10bb30385b38288c9037afc066db121483858f132bfa39bcd0d5a94e744665d4436d30d29987888e714dfcb88
6
+ metadata.gz: f78e9cbec54f20211bf9533e5958e1bb314046fd4d950d439675a6274d7a922ca160c1773a92bc311ff2151e110ec3d424efff6004404ac46eca2deea4daaced
7
+ data.tar.gz: 734c11e4e6352af74e1be6fdf2402ee7e163a9c56f00bf4fc011d905e2f374a9be98a5806120170f8af4801c2cf7875d6813ffef096b822566a5f8f1a97ec6ab
@@ -41,6 +41,9 @@ The default rake task uses [WWTD] to test multiple versions of RSpec.
41
41
 
42
42
  ``` ruby
43
43
  rake
44
+
45
+ # with a formatter
46
+ FORMATTER=Nc rake
44
47
  ```
45
48
 
46
49
  [WWTD]: https://github.com/grosser/wwtd
data/Rakefile CHANGED
@@ -4,6 +4,8 @@ require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
5
  require 'wwtd/tasks'
6
6
 
7
- RSpec::Core::RakeTask.new(:spec)
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = "--format=#{ENV['FORMATTER']}" if ENV['FORMATTER']
9
+ end
8
10
 
9
11
  task :default => :wwtd
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
- if RSpec::Core::Formatters.respond_to? :register
6
- RSpec::Core::Formatters.register self.class, :example_failed
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(duration, example_count, failure_count, pending_count)
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
@@ -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
@@ -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(duration, example_count, failure_count, pending_count)
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
@@ -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.1.1'
4
+ gem.version = '0.2.0'
5
5
  gem.authors = ['Odin Dutton']
6
6
  gem.email = ['odindutton@gmail.com']
7
7
  gem.description = 'https://github.com/twe4ked/rspec-nc'
@@ -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
- it 'notifies the first failure only' do
14
- allow(example).to receive(:metadata).and_return({:full_description => description})
15
- allow(example).to receive(:exception).and_return(exception)
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
- expect(TerminalNotifier).to receive(:notify).with("#{description}\n#{exception}",
18
- :title => "#{failure} #{current_dir}: Failure"
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
- formatter.example_failed(example)
22
- formatter.example_failed(example2)
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
- it "doesn't notify in the end if there has been any failures" do
26
- expect(TerminalNotifier).to_not receive(:notify)
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
- formatter.dump_summary(0.0001, 2, 1, 0)
83
+ formatter.dump_summary(success_notification)
84
+ end
29
85
  end
30
86
  end
@@ -8,30 +8,54 @@ describe Nc do
8
8
  let(:success) { "\u2705" }
9
9
  let(:failure) { "\u26D4" }
10
10
 
11
- it 'returns the summary' do
12
- expect(TerminalNotifier).to receive(:notify).with(
13
- "Finished in 0.0001 seconds\n3 examples, 1 failure, 1 pending",
14
- :title => "#{failure} #{current_dir}: 1 failed example"
15
- )
16
-
17
- formatter.dump_summary(0.0001, 3, 1, 1)
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
- it 'returns a failing notification' do
21
- expect(TerminalNotifier).to receive(:notify).with(
22
- "Finished in 0.0001 seconds\n1 example, 1 failure",
23
- :title => "#{failure} #{current_dir}: 1 failed example"
24
- )
25
-
26
- formatter.dump_summary(0.0001, 1, 1, 0)
27
- end
28
-
29
- it 'returns a success notification' do
30
- expect(TerminalNotifier).to receive(:notify).with(
31
- "Finished in 0.0001 seconds\n1 example, 0 failures",
32
- :title => "#{success} #{current_dir}: Success"
33
- )
34
-
35
- formatter.dump_summary(0.0001, 1, 0, 0)
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.1.1
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-07-28 00:00:00.000000000 Z
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: terminal-notifier