rspec-kungfuhamster 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: cdeade8d8542b627204a981d63260b3ded4c3eb08258f66ea7f7e49e482b8f61
4
- data.tar.gz: befdc3608a08866bc7d9c1556ee54283993a4068db106b607fd6a96c0a980a3d
3
+ metadata.gz: c92b0b0f6f0bb783ebb702f632f63542425c84556ca4f3982551220be557a437
4
+ data.tar.gz: eb84f0c9f932383e949bb4ea8ddbdb1e6aecfe3bd6be3d5a7057104dd3fa60fe
5
5
  SHA512:
6
- metadata.gz: 6d9013150c705bb88c75067d9af425f4a65f7b5abed6779694f61fea85137bfc5d8b0ffa230fa06bb1fc888dcc40c3e4a02d91104ff957fed6d97b635a467c27
7
- data.tar.gz: 99e1e684ffb1e0290ae84b8174a28f2d33d5cbe42461d5c21cec3f3d2617c834cb7ce7b0c2aa801ffbb7be8f7f34a05f26b6cc8c6ff8fda224ddd2758a085a6e
6
+ metadata.gz: 971532e9801222edb9a37cd33c229f31416237dc0700ea0d534b27ba5f97a7a79e4edbe34dc4c745f6a2711f85f0103179cffc64a8b0388298c01050a2011569
7
+ data.tar.gz: e5ee98e22bd26f55a193c84d92816cb233289cb5def1abac3dbd9ebbbbcc07e62133f0602054f7c565f31c6147a56a1b57be39eb44623c93c7047c5a5d0df611
data/README.md CHANGED
@@ -34,12 +34,30 @@ gem 'rspec-kungfuhamster'
34
34
 
35
35
  After installing the gem, you can use the formatter in several ways:
36
36
 
37
+ ## Formatters
38
+
39
+ The gem provides two formatters:
40
+
41
+ ### Basic Formatter
42
+
43
+ The basic formatter shows just the animated kung fu hamster with color-coded animation.
44
+
45
+ ### Detailed Formatter
46
+
47
+ The detailed formatter shows the animated kung fu hamster with additional information below:
48
+ - Color-coded statistics (passed/pending/failed out of total examples)
49
+ - Last spec file that was executed
50
+
37
51
  ## Command Line
38
52
 
39
53
  Run RSpec with the formatter specified:
40
54
 
41
55
  ```bash
56
+ # Basic formatter
42
57
  rspec --format RspecKungFuHamster::Formatter
58
+
59
+ # Detailed formatter
60
+ rspec --format RspecKungFuHamster::DetailedFormatter
43
61
  ```
44
62
 
45
63
  ## Configuration File
@@ -47,7 +65,11 @@ rspec --format RspecKungFuHamster::Formatter
47
65
  Add to your `.rspec` file in your project root:
48
66
 
49
67
  ```
68
+ # Basic formatter
50
69
  --format RspecKungFuHamster::Formatter
70
+
71
+ # OR detailed formatter
72
+ --format RspecKungFuHamster::DetailedFormatter
51
73
  ```
52
74
 
53
75
  ## RSpec Configuration
@@ -56,7 +78,11 @@ Add to your `spec/spec_helper.rb` or `spec/rails_helper.rb`:
56
78
 
57
79
  ```ruby
58
80
  RSpec.configure do |config|
81
+ # Basic formatter
59
82
  config.formatter = RspecKungFuHamster::Formatter
83
+
84
+ # OR detailed formatter
85
+ config.formatter = RspecKungFuHamster::DetailedFormatter
60
86
  end
61
87
  ```
62
88
 
@@ -65,7 +91,7 @@ Or if you want to use multiple formatters:
65
91
  ```ruby
66
92
  RSpec.configure do |config|
67
93
  config.formatter = :progress # or :documentation
68
- config.add_formatter RspecKungFuHamster::Formatter
94
+ config.add_formatter RspecKungFuHamster::DetailedFormatter
69
95
  end
70
96
  ```
71
97
 
@@ -0,0 +1,52 @@
1
+ require 'rspec_kung_fu_hamster/formatter'
2
+
3
+ module RspecKungFuHamster
4
+ class DetailedFormatter < Formatter
5
+ RSpec::Core::Formatters.register self,
6
+ :example_passed,
7
+ :example_pending,
8
+ :example_failed,
9
+ :example_group_started
10
+
11
+ def initialize(output)
12
+ @last_spec_file = nil
13
+ super(output)
14
+ end
15
+
16
+ def example_group_started(notification)
17
+ # Track the file path of the current example group
18
+ if notification.group.metadata[:file_path]
19
+ @last_spec_file = notification.group.metadata[:file_path]
20
+ end
21
+ end
22
+
23
+ def output_hamster
24
+ output.puts "\e[2J\e[;H" + display(hamster_and_next) + "\n" + stats_display
25
+ end
26
+
27
+ def stats_display
28
+ total = @example_passed + @example_pending + @example_failed
29
+ return "" if total == 0
30
+
31
+ lines = []
32
+ lines << "" # Blank line for spacing
33
+
34
+ # Color-coded statistics
35
+ stats_parts = []
36
+ stats_parts << "#{GREEN}#{@example_passed} passed#{RESET}" if @example_passed > 0
37
+ stats_parts << "#{YELLOW}#{@example_pending} pending#{RESET}" if @example_pending > 0
38
+ stats_parts << "#{RED}#{@example_failed} failed#{RESET}" if @example_failed > 0
39
+
40
+ lines << "#{stats_parts.join(', ')} out of #{total} examples"
41
+
42
+ # Display last spec file
43
+ if @last_spec_file
44
+ # Clean up the file path to show relative path
45
+ display_path = @last_spec_file.sub(Dir.pwd + '/', '')
46
+ lines << "Last file: #{display_path}"
47
+ end
48
+
49
+ lines.join("\n")
50
+ end
51
+ end
52
+ end
@@ -1 +1,117 @@
1
- require 'rspec_kung_fu_hamster'
1
+ require 'rspec'
2
+ require 'rspec/core/formatters/base_text_formatter'
3
+
4
+ module RspecKungFuHamster
5
+ class Formatter < RSpec::Core::Formatters::BaseTextFormatter
6
+ RSpec::Core::Formatters.register self,
7
+ :example_passed,
8
+ :example_pending,
9
+ :example_failed
10
+
11
+ def initialize(output)
12
+ @index = 0
13
+ @example_passed = 0
14
+ @example_pending = 0
15
+ @example_failed = 0
16
+ super(output)
17
+ end
18
+
19
+ def color_positions(length)
20
+ total = @example_passed + @example_pending + @example_failed
21
+ passed_percent = @example_passed * length / total
22
+ pending_percent = @example_pending * length / total
23
+
24
+ [passed_percent, passed_percent + pending_percent, length]
25
+ end
26
+
27
+ GREEN = "\e[32m"
28
+ YELLOW = "\e[33m"
29
+ RED = "\e[31m"
30
+ RESET = "\e[0m"
31
+
32
+ def colorize(string)
33
+ green, yellow, red = color_positions(string.length)
34
+ GREEN + string[0...green] + YELLOW + string[green...yellow] + RED + string[yellow...red] + RESET
35
+ end
36
+
37
+ def display(strings)
38
+ colorize(strings.join("\n"))
39
+ end
40
+
41
+ def output_hamster
42
+ output.puts "\e[2J\e[;H" + display(hamster_and_next)
43
+ end
44
+
45
+ def example_passed(notification)
46
+ @example_passed += 1
47
+ output_hamster
48
+ end
49
+
50
+ def example_pending(notification)
51
+ @example_pending += 1
52
+ output_hamster
53
+ end
54
+
55
+ def example_failed(notification)
56
+ @example_failed += 1
57
+ output_hamster
58
+ end
59
+
60
+ def hamster_and_next
61
+ KUNG_FU_HAMSTER[@index % KUNG_FU_HAMSTER.length].tap { @index += 1 }
62
+ end
63
+
64
+ KUNG_FU_HAMSTER = [
65
+ [
66
+ " ()__() ",
67
+ " / o o\\ | ",
68
+ " |' =Y=';-| ",
69
+ " { \\ / } ",
70
+ " mmm mmm "
71
+ ],
72
+ [
73
+ " ()__() ",
74
+ " / o o\\ ; ",
75
+ " |' =Y=';-/ ",
76
+ " { \\ / } ",
77
+ " mmm mmm "
78
+ ],
79
+ [
80
+ " ()__() ",
81
+ " / o o\\ ",
82
+ " |' =Y=';----",
83
+ " { \\ / } ",
84
+ " mmm mmm "
85
+ ],
86
+ [
87
+ " ()__() ",
88
+ " / o o\\ ",
89
+ " |' =Y=';-\\ ",
90
+ " { \\ / } \\ ",
91
+ " mmm mmm "
92
+ ],
93
+ [
94
+ " ()__() ",
95
+ " / o o\\ ",
96
+ " |' =Y=';----",
97
+ " { \\ / } ",
98
+ " mmm mmm "
99
+ ],
100
+ [
101
+ " ()__() ",
102
+ " / o o\\ \\ ",
103
+ " |' =Y=';-\\ ",
104
+ " { \\ / } ",
105
+ " mmm mmm "
106
+ ]
107
+ ]
108
+
109
+ DEAD_HAMSTER = [
110
+ " ()__() ",
111
+ " / X X\\ | ",
112
+ " |' =Y=';-| ",
113
+ " { \\ / } ",
114
+ " mmm mmm "
115
+ ]
116
+ end
117
+ end
@@ -1,3 +1,3 @@
1
1
  module RspecKungFuHamster
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,115 +1,3 @@
1
- require 'rspec'
2
- require 'rspec/core/formatters/base_text_formatter'
3
1
  require 'rspec_kung_fu_hamster/version'
4
-
5
- rspec_bin = $0.split('/').last
6
-
7
- module RspecKungFuHamster
8
- class Formatter < RSpec::Core::Formatters::BaseTextFormatter
9
- RSpec::Core::Formatters.register self,
10
- # :start,
11
- # :example_start
12
- # :message,
13
- :example_passed,
14
- :example_pending,
15
- :example_failed
16
- # :dump_failures
17
-
18
- def initialize(output)
19
- @index = 0
20
- @example_passed = 0
21
- @example_pending = 0
22
- @example_failed = 0
23
- super(output)
24
- end
25
-
26
- def color_positions(length)
27
- total = @example_passed + @example_pending + @example_failed
28
- passed_percent = @example_passed * length / total
29
- pending_percent = @example_pending * length / total
30
-
31
- [passed_percent, passed_percent + pending_percent, length]
32
- end
33
-
34
- GREEN = "\e[32m"
35
- YELLOW = "\e[33m"
36
- RED = "\e[31m"
37
- RESET = "\e[0m"
38
-
39
- def colorize(string)
40
- green, yellow, red = color_positions(string.length)
41
- GREEN + string[0...green] + YELLOW + string[green...yellow] + RED + string[yellow...red] + RESET
42
- end
43
-
44
- def display(strings)
45
- colorize(strings.join("\n"))
46
- end
47
-
48
- def output_hamster
49
- output.puts "\e[2J\e[;H" + display(hamster_and_next)
50
- end
51
- def example_passed(notification)
52
- @example_passed += 1
53
- output_hamster
54
- end
55
- def example_pending(notification)
56
- @example_pending += 1
57
- output_hamster
58
- end
59
- def example_failed(notification)
60
- @example_failed += 1
61
- output_hamster
62
- end
63
-
64
- def hamster_and_next
65
- KUNG_FU_HAMSTER[@index % KUNG_FU_HAMSTER.length].tap { @index += 1 }
66
- end
67
-
68
- KUNG_FU_HAMSTER = [
69
- [
70
- " ()__() ",
71
- " / o o\\ | ",
72
- " |' =Y=';-| ",
73
- " { \\ / } ",
74
- " mmm mmm "
75
- ],[
76
- " ()__() ",
77
- " / o o\\ ; ",
78
- " |' =Y=';-/ ",
79
- " { \\ / } ",
80
- " mmm mmm "
81
- ],[
82
- " ()__() ",
83
- " / o o\\ ",
84
- " |' =Y=';----",
85
- " { \\ / } ",
86
- " mmm mmm "
87
- ],[
88
- " ()__() ",
89
- " / o o\\ ",
90
- " |' =Y=';-\\ ",
91
- " { \\ / } \\ ",
92
- " mmm mmm "
93
- ],[
94
- " ()__() ",
95
- " / o o\\ ",
96
- " |' =Y=';----",
97
- " { \\ / } ",
98
- " mmm mmm "
99
- ],[
100
- " ()__() ",
101
- " / o o\\ \\ ",
102
- " |' =Y=';-\\ ",
103
- " { \\ / } ",
104
- " mmm mmm "
105
- ]]
106
-
107
- DEAD_HAMSTER = [
108
- " ()__() ",
109
- " / X X\\ | ",
110
- " |' =Y=';-| ",
111
- " { \\ / } ",
112
- " mmm mmm "
113
- ]
114
- end
115
- end
2
+ require 'rspec_kung_fu_hamster/formatter'
3
+ require 'rspec_kung_fu_hamster/detailed_formatter'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-kungfuhamster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Powell
@@ -35,6 +35,7 @@ files:
35
35
  - LICENSE
36
36
  - README.md
37
37
  - lib/rspec_kung_fu_hamster.rb
38
+ - lib/rspec_kung_fu_hamster/detailed_formatter.rb
38
39
  - lib/rspec_kung_fu_hamster/formatter.rb
39
40
  - lib/rspec_kung_fu_hamster/version.rb
40
41
  - spec/kungfuhamster_spec.rb