luna-rspec-formatters 3.3.2 → 3.4.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: 34808699734331bb8e0ee5939f4f4a30baa39505
4
- data.tar.gz: 7f706e4f352629f2ee2e3d647897fb6517eea655
3
+ metadata.gz: 2736dd9bc87741064d0ff98dfbbf2780379a5ee3
4
+ data.tar.gz: dac892532d6d808967e7f7468176d87136fa41ca
5
5
  SHA512:
6
- metadata.gz: 9fdf6ddb69f0a8e9313c6f45f31243979009a358338ebfa6a5e33488b0c9166c72e0ad4b0cb84d4a47bf20ae88729657a2fedd749c9b710d101406d958e2ebc4
7
- data.tar.gz: f460a6303dcdc1803d25592a313511b1b63d0046d43f370429ab1c351eac2a70e6d39a2d1c870cbc62d04632d35049518f43b3a14f8eecda007fbcf446784277
6
+ metadata.gz: 5b02dfe478d03cf3b8c6960cdbfa2e589cdd9d3b5a40e914002bf8eca82bf847f7ce6a8c19857a77ad5caceb2cc11383d7353badbeb96968de757147ce7e69b8
7
+ data.tar.gz: 4e0e36bd0d0edc864f5f3ba789c082a7d3287b29428c3880eed1d120fc0f2569b903d5f930df2196ec0cddbe1d80b166be040b7e8f9104a5304e5ecf7a1ed47e
data/README.md CHANGED
@@ -4,12 +4,15 @@
4
4
  gem "luna-rspec-formatters"
5
5
  ```
6
6
 
7
- A set of `rspec` formatters that design things the way I like them. `Doc2` is
8
- a formatter that outputs the full description as a single line rather than
7
+ A set of `rspec` formatters that design things the way I like them. `fulldesc`
8
+ is a formatter that outputs the full description as a single line rather than
9
9
  nesting like documentation and `Checks` displays checkmark's and other UTF
10
10
  characters rather than dots.
11
11
 
12
12
  ```ruby
13
13
  require "luna/rspec/formatters/checks"
14
- require "luna/rspec/formatters/documentation"
14
+ require "luna/rspec/formatters/fulldesc"
15
+ require "luna/rspec/formatters/smilies"
16
+ require "luna/rspec/formatters/hearts"
17
+ require "luna/rspec/formatters/cats"
15
18
  ```
@@ -0,0 +1,45 @@
1
+ require "luna/rspec/formatters/emoji"
2
+
3
+ module Luna
4
+ module RSpec
5
+ module Formatters
6
+ class Smilies < Emoji
7
+ if Gem::Version.new(::RSpec::Version::STRING) >= Gem::Version.new("3.0")
8
+ ::RSpec::Core::Formatters.register self, *[
9
+ :start,
10
+ :start_dump,
11
+ :example_passed,
12
+ :example_pending,
13
+ :example_failed,
14
+ :dump_profile
15
+ ]
16
+ end
17
+
18
+ def example_passed(e)
19
+ newline_or_addup
20
+ output.print " ".freeze, success_color(
21
+ "\u1F63B"
22
+ )
23
+ end
24
+
25
+ def example_failed(e)
26
+ newline_or_addup
27
+ output.print " ".freeze, failure_color(
28
+ "\u1F63E"
29
+ )
30
+ end
31
+
32
+ def example_pending(e)
33
+ newline_or_addup
34
+ output.print " ".freeze, pending_color(
35
+ "\u1F63F"
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ RSpec.configure do |config|
44
+ config.formatter = "Luna::RSpec::Formatters::Smilies"
45
+ end
@@ -1,52 +1,41 @@
1
- require "rspec/core/formatters/base_text_formatter"
2
- require "luna/rspec/formatters/profile"
3
- require "rspec/version"
1
+ require "luna/rspec/formatters/emoji"
4
2
 
5
3
  module Luna
6
4
  module RSpec
7
5
  module Formatters
8
- class Checks < ::RSpec::Core::Formatters::BaseTextFormatter
6
+ class Checks < Emoji
9
7
  include Profile
10
8
 
11
- if ::RSpec::Version::STRING >= "3.0.0"
12
- # Probably not available in the old version of RSpec.
13
- then ::RSpec::Core::Formatters.register self, :start, :start_dump, \
14
- :example_passed, :example_pending, :example_failed, :dump_profile
15
- end
16
-
17
- [:success, :failure, :pending].each do |m|
18
- define_method "#{m}_color" do |v|
19
- defined?(super) ? super(v) : \
20
- ::RSpec::Core::Formatters::ConsoleCodes.wrap(v, m)
21
- end
22
- end
23
-
24
- def start(*args)
25
- super(*args) if defined?(super)
26
- output.puts
27
- end
28
-
29
- def start_dump(*args)
30
- super(*args) if defined?(super)
31
- output.puts
9
+ if Gem::Version.new(::RSpec::Version::STRING) >= Gem::Version.new("3.0")
10
+ ::RSpec::Core::Formatters.register self, *[
11
+ :start,
12
+ :start_dump,
13
+ :example_passed,
14
+ :example_pending,
15
+ :example_failed,
16
+ :dump_profile
17
+ ]
32
18
  end
33
19
 
34
20
  def example_passed(e)
35
- super(e) if defined?(super)
36
- output.print("\s")
37
- output.print(success_color("\u2713"))
21
+ newline_or_addup
22
+ output.print " ".freeze, success_color(
23
+ "\u2714"
24
+ )
38
25
  end
39
26
 
40
27
  def example_failed(e)
41
- super(e) if defined?(super)
42
- output.print("\s")
43
- output.print(failure_color("\u2718"))
28
+ newline_or_addup
29
+ output.print " ".freeze, failure_color(
30
+ "\u2718"
31
+ )
44
32
  end
45
33
 
46
34
  def example_pending(e)
47
- super(e) if defined?(super)
48
- output.print("\s")
49
- output.print(pending_color("\u203D"))
35
+ newline_or_addup
36
+ output.print " ".freeze, pending_color(
37
+ "\u203D"
38
+ )
50
39
  end
51
40
  end
52
41
  end
@@ -0,0 +1,38 @@
1
+ require "rspec/core/formatters/base_text_formatter"
2
+ require "luna/rspec/formatters/profile"
3
+ require "rspec/version"
4
+
5
+ module Luna
6
+ module RSpec
7
+ module Formatters
8
+ class Emoji < ::RSpec::Core::Formatters::BaseTextFormatter
9
+ include Profile
10
+
11
+ [:success, :failure, :pending].each do |m|
12
+ define_method "#{m}_color" do |v|
13
+ defined?(super) ? super(v) : \
14
+ ::RSpec::Core::Formatters::ConsoleCodes.wrap(v, m)
15
+ end
16
+ end
17
+
18
+ def allowed_cols
19
+ @cols ||= (`tput cols 2>/dev/null || 80`.to_i / 1.6).floor
20
+ end
21
+
22
+ def start(*args)
23
+ @lines = 0
24
+ output.puts
25
+ end
26
+
27
+ def start_dump(*args)
28
+ output.puts
29
+ end
30
+
31
+ private
32
+ def newline_or_addup
33
+ @lines == allowed_cols ? (output.puts; @lines = 1) : @lines+=1
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,77 @@
1
+ require "rspec/core/formatters/base_text_formatter"
2
+ require "luna/rspec/formatters/profile"
3
+ require "rspec/version"
4
+ require "coderay"
5
+
6
+ module Luna
7
+ module RSpec
8
+ module Formatters
9
+ class Documentation < ::RSpec::Core::Formatters::BaseTextFormatter
10
+ include Profile
11
+
12
+ if Gem::Version.new(::RSpec::Version::STRING) >= Gem::Version.new("3.0")
13
+ ::RSpec::Core::Formatters.register self, *[
14
+ :start,
15
+ :start_dump,
16
+ :example_passed,
17
+ :example_pending,
18
+ :example_failed,
19
+ :dump_profile
20
+ ]
21
+ end
22
+
23
+ [:success, :failure, :pending].each do |m|
24
+ define_method "#{m}_color" do |v|
25
+ defined?(super) ? super(v) : ::RSpec::Core::Formatters::ConsoleCodes.wrap(
26
+ v, m
27
+ )
28
+ end
29
+ end
30
+
31
+ def start(*args)
32
+ output.puts
33
+ end
34
+
35
+ def start_dump(*args)
36
+ output.puts
37
+ end
38
+
39
+ def example_passed(struct)
40
+ output.print "\s"
41
+ print_description(
42
+ get_example(struct), :success
43
+ )
44
+ end
45
+
46
+ def example_failed(struct)
47
+ output.print "\s"
48
+ print_description(
49
+ get_example(struct), :failure
50
+ )
51
+ end
52
+
53
+ def example_pending(struct)
54
+ output.print "\s"
55
+ print_description(
56
+ get_example(struct), :pending
57
+ )
58
+ end
59
+
60
+ def get_example(struct)
61
+ return struct unless struct.respond_to?(:example)
62
+ struct.example
63
+ end
64
+
65
+ def print_description(example, type)
66
+ output.print send(
67
+ :"#{type}_color", " " + example.full_description + "\n"
68
+ )
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ RSpec.configure do |config|
76
+ config.formatter = "Luna::RSpec::Formatters::Documentation"
77
+ end
@@ -0,0 +1,45 @@
1
+ require "luna/rspec/formatters/emoji"
2
+
3
+ module Luna
4
+ module RSpec
5
+ module Formatters
6
+ class Hearts < Emoji
7
+ if Gem::Version.new(::RSpec::Version::STRING) >= Gem::Version.new("3.0")
8
+ ::RSpec::Core::Formatters.register self, *[
9
+ :start,
10
+ :start_dump,
11
+ :example_passed,
12
+ :example_pending,
13
+ :example_failed,
14
+ :dump_profile
15
+ ]
16
+ end
17
+
18
+ def example_passed(e)
19
+ newline_or_addup
20
+ output.print " ".freeze, success_color(
21
+ "\u2764"
22
+ )
23
+ end
24
+
25
+ def example_failed(e)
26
+ newline_or_addup
27
+ output.print " ".freeze, failure_color(
28
+ "\u1F494"
29
+ )
30
+ end
31
+
32
+ def example_pending(e)
33
+ newline_or_addup
34
+ output.print " ".freeze, pending_color(
35
+ "\u2764"
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ RSpec.configure do |config|
44
+ config.formatter = "Luna::RSpec::Formatters::Hearts"
45
+ end
@@ -2,10 +2,10 @@ module Luna
2
2
  module RSpec
3
3
  module Formatters
4
4
  module Profile
5
- EXAMPLES = " %{description} %{seconds} seconds: %{location}"
6
- GROUPS = " %{description} %{total} seconds over %{count} examples: %{location}"
5
+ GROUPS = " %{location} \u2910 %{count} for %{total}"
7
6
  EXAMPLES_HEADER = "\nTop %{size} slowest examples (%{seconds}s), %{per_cent}%% of total time:\n"
8
7
  GROUPS_HEADER = "\nTop %{size} slowest example groups:"
8
+ EXAMPLES = " %{location} \u2910 %{seconds}"
9
9
 
10
10
 
11
11
  def helpers
@@ -14,40 +14,38 @@ module Luna
14
14
 
15
15
  def dump_profile(profile)
16
16
  dump_profile_slowest_examples(profile)
17
- dump_profile_slowest_example_groups(profile)
17
+ dump_profile_slowest_example_groups(
18
+ profile
19
+ )
18
20
  end
19
21
 
20
22
  private
21
23
  def dump_profile_slowest_examples(profile)
22
- unless profile.slowest_examples.any? { |e| e.execution_result.run_time >= 0.2 }
23
- return
24
- end
25
-
26
24
  examples_header(profile)
27
25
  profile.slowest_examples.each do |e|
26
+ sec = helpers.format_seconds(e.execution_result.run_time) + \
27
+ " seconds"
28
+
28
29
  @output.puts EXAMPLES % {
29
30
  location: format_caller(e.location),
30
- seconds: failure_color(helpers.format_seconds(e.execution_result.run_time)),
31
+ seconds: sec.to_f < 1 ? success_color(sec) : failure_color(sec),
31
32
  description: e.full_description
32
33
  }
33
34
  end
34
35
  end
35
36
 
36
37
  def dump_profile_slowest_example_groups(profile)
37
- unless !profile.slowest_groups.empty? && \
38
- profile.slowest_groups.any? { |l, h| h[:average] >= 0.4 }
39
-
40
- return
41
- end
42
-
43
38
  groups_header(profile)
44
39
  profile.slowest_groups.each do |l, h|
45
- @output.puts GROUPS % {
40
+ sec = helpers.format_seconds(h[:total_time]) + \
41
+ "seconds"
42
+
43
+ @output.puts color_blue(GROUPS % {
46
44
  description: h[:description],
47
- total: failure_color(helpers.format_seconds(h[:total_time])),
48
- count: helpers.pluralize(h[:count], "example"),
49
- location: l
50
- }
45
+ total: sec.to_f < 2 ? success_color(sec) : failure_color(sec),
46
+ location: color_blue(strip_relative(l)),
47
+ count: h[:count]
48
+ })
51
49
  end
52
50
  end
53
51
 
@@ -65,10 +63,22 @@ module Luna
65
63
  }
66
64
  end
67
65
 
66
+ def color_blue(str)
67
+ ::RSpec::Core::Formatters::ConsoleCodes.wrap(
68
+ str, :cyan
69
+ )
70
+ end
71
+
72
+ def strip_relative(path)
73
+ path.gsub(
74
+ /\A\.\//, ""
75
+ )
76
+ end
77
+
68
78
  def format_caller(caller_info)
69
- ::RSpec.configuration.backtrace_formatter.backtrace_line(
79
+ color_blue strip_relative(::RSpec.configuration.backtrace_formatter.backtrace_line(
70
80
  caller_info.to_s.split(':in `block').first
71
- )
81
+ ))
72
82
  end
73
83
  end
74
84
  end
@@ -0,0 +1,45 @@
1
+ require "luna/rspec/formatters/emoji"
2
+
3
+ module Luna
4
+ module RSpec
5
+ module Formatters
6
+ class Smilies < Emoji
7
+ if Gem::Version.new(::RSpec::Version::STRING) >= Gem::Version.new("3.0")
8
+ ::RSpec::Core::Formatters.register self, *[
9
+ :start,
10
+ :start_dump,
11
+ :example_passed,
12
+ :example_pending,
13
+ :example_failed,
14
+ :dump_profile
15
+ ]
16
+ end
17
+
18
+ def example_passed(e)
19
+ newline_or_addup
20
+ output.print " ".freeze, success_color(
21
+ "\u263A"
22
+ )
23
+ end
24
+
25
+ def example_failed(e)
26
+ newline_or_addup
27
+ output.print " ".freeze, failure_color(
28
+ "\u2639"
29
+ )
30
+ end
31
+
32
+ def example_pending(e)
33
+ newline_or_addup
34
+ output.print " ".freeze, pending_color(
35
+ "\u2639"
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ RSpec.configure do |config|
44
+ config.formatter = "Luna::RSpec::Formatters::Smilies"
45
+ end
@@ -1,7 +1,7 @@
1
1
  module Luna
2
2
  module Rspec
3
3
  module Formatters
4
- VERSION = "3.3.2"
4
+ VERSION = "3.4.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luna-rspec-formatters
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.2
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordon Bedwell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-25 00:00:00.000000000 Z
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -40,9 +40,13 @@ files:
40
40
  - Gemfile
41
41
  - LICENSE
42
42
  - README.md
43
+ - lib/luna/rspec/formatters/cats.rb
43
44
  - lib/luna/rspec/formatters/checks.rb
44
- - lib/luna/rspec/formatters/documentation.rb
45
+ - lib/luna/rspec/formatters/emoji.rb
46
+ - lib/luna/rspec/formatters/fulldesc.rb
47
+ - lib/luna/rspec/formatters/hearts.rb
45
48
  - lib/luna/rspec/formatters/profile.rb
49
+ - lib/luna/rspec/formatters/smilies.rb
46
50
  - lib/luna/rspec/formatters/version.rb
47
51
  homepage: https://github.com/envygeeks/luna-rspec-formatters
48
52
  licenses:
@@ -64,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
68
  version: '0'
65
69
  requirements: []
66
70
  rubyforge_project:
67
- rubygems_version: 2.4.8
71
+ rubygems_version: 2.5.0
68
72
  signing_key:
69
73
  specification_version: 4
70
74
  summary: RSpec formatters dedicated to Luna.
@@ -1,61 +0,0 @@
1
- require "rspec/core/formatters/base_text_formatter"
2
- require "luna/rspec/formatters/profile"
3
- require "rspec/version"
4
- require "coderay"
5
-
6
- module Luna
7
- module RSpec
8
- module Formatters
9
- class Documentation < ::RSpec::Core::Formatters::BaseTextFormatter
10
- include Profile
11
-
12
- if ::RSpec::Version::STRING >= "3.0.0"
13
- # Probably not available in the old version of RSpec.
14
- ::RSpec::Core::Formatters.register self, :start, :start_dump, \
15
- :example_passed, :example_pending, :example_failed, :dump_profile
16
- end
17
-
18
- [:success, :failure, :pending].each do |m|
19
- define_method "#{m}_color" do |v|
20
- defined?(super) ? super(v) : \
21
- ::RSpec::Core::Formatters::ConsoleCodes.wrap(v, m)
22
- end
23
- end
24
-
25
- def start(*args)
26
- super(*args) if defined?(super)
27
- output.puts
28
- end
29
-
30
- def start_dump(*args)
31
- super(*args) if defined?(super)
32
- output.puts
33
- end
34
-
35
- def example_passed(e)
36
- output.print("\s")
37
- print_description(e, :success)
38
- end
39
-
40
- def example_failed(e)
41
- output.print("\s")
42
- print_description(e, :failure)
43
- end
44
-
45
- def example_pending(e)
46
- output.print("\s")
47
- print_description(e, :pending)
48
- end
49
-
50
- def print_description(example, type)
51
- output.print send(:"#{type}_color",
52
- "\t" + example.full_description + "\n")
53
- end
54
- end
55
- end
56
- end
57
- end
58
-
59
- RSpec.configure do |config|
60
- config.formatter = "Luna::RSpec::Formatters::Documentation"
61
- end