rspec-kungfuhamster 0.1.1 → 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
- SHA1:
3
- metadata.gz: ecb64e5c8de36ef5855f65f928d1a34b6a66159e
4
- data.tar.gz: 55588280b3b71c1009d421e4fb39f3562333a887
2
+ SHA256:
3
+ metadata.gz: c92b0b0f6f0bb783ebb702f632f63542425c84556ca4f3982551220be557a437
4
+ data.tar.gz: eb84f0c9f932383e949bb4ea8ddbdb1e6aecfe3bd6be3d5a7057104dd3fa60fe
5
5
  SHA512:
6
- metadata.gz: 9a718ff778697d3f140735a0c5fe130538378ce281bfc1cb94ee5c18d2f6278057242c1f2c35a61423b35bf8a84082c9eaefb2e8e4cf7c31ee3878ffa3e47d2b
7
- data.tar.gz: c3e31df35c776c24a4f7e0bd08c7f671ddd4f1bc2c46843f8c81c992c487bb4bc99a15f62d45453855a0214596806cf663217e41d0d7f63d8b9dca3d8d276894
6
+ metadata.gz: 971532e9801222edb9a37cd33c229f31416237dc0700ea0d534b27ba5f97a7a79e4edbe34dc4c745f6a2711f85f0103179cffc64a8b0388298c01050a2011569
7
+ data.tar.gz: e5ee98e22bd26f55a193c84d92816cb233289cb5def1abac3dbd9ebbbbcc07e62133f0602054f7c565f31c6147a56a1b57be39eb44623c93c7047c5a5d0df611
data/README.md CHANGED
@@ -3,10 +3,118 @@ rspec-kungfuhamster
3
3
 
4
4
  Animated kung fu hamster formatter
5
5
 
6
+ # Sample Output
7
+
8
+ As your tests run, you'll see an animated kung fu hamster performing various martial arts moves:
9
+
10
+ ```
11
+ ()__()
12
+ / o o\
13
+ |' =Y=';----
14
+ { \ / }
15
+ mmm mmm
16
+ ```
17
+
18
+ The hamster is colorized based on your test results:
19
+ - **Green** portion: Passing tests
20
+ - **Yellow** portion: Pending tests
21
+ - **Red** portion: Failing tests
22
+
23
+ The hamster cycles through different kung fu poses as each test completes, creating an animated effect in your terminal!
24
+
6
25
  # Installation
7
26
 
8
- Add this to you Gemfile (in the test group) and run `bundle install`:
27
+ Add this to your Gemfile (in the test group) and run `bundle install`:
9
28
 
10
29
  ``` ruby
11
30
  gem 'rspec-kungfuhamster'
12
31
  ```
32
+
33
+ # Usage
34
+
35
+ After installing the gem, you can use the formatter in several ways:
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
+
51
+ ## Command Line
52
+
53
+ Run RSpec with the formatter specified:
54
+
55
+ ```bash
56
+ # Basic formatter
57
+ rspec --format RspecKungFuHamster::Formatter
58
+
59
+ # Detailed formatter
60
+ rspec --format RspecKungFuHamster::DetailedFormatter
61
+ ```
62
+
63
+ ## Configuration File
64
+
65
+ Add to your `.rspec` file in your project root:
66
+
67
+ ```
68
+ # Basic formatter
69
+ --format RspecKungFuHamster::Formatter
70
+
71
+ # OR detailed formatter
72
+ --format RspecKungFuHamster::DetailedFormatter
73
+ ```
74
+
75
+ ## RSpec Configuration
76
+
77
+ Add to your `spec/spec_helper.rb` or `spec/rails_helper.rb`:
78
+
79
+ ```ruby
80
+ RSpec.configure do |config|
81
+ # Basic formatter
82
+ config.formatter = RspecKungFuHamster::Formatter
83
+
84
+ # OR detailed formatter
85
+ config.formatter = RspecKungFuHamster::DetailedFormatter
86
+ end
87
+ ```
88
+
89
+ Or if you want to use multiple formatters:
90
+
91
+ ```ruby
92
+ RSpec.configure do |config|
93
+ config.formatter = :progress # or :documentation
94
+ config.add_formatter RspecKungFuHamster::DetailedFormatter
95
+ end
96
+ ```
97
+
98
+ # Development
99
+
100
+ ## Automated Version Bumping
101
+
102
+ This gem uses automated version bumping on pull requests merged to `main` or `master`. The version bump type is determined by labels on the PR:
103
+
104
+ - **`major`** label: Bumps the major version (e.g., 1.2.3 → 2.0.0)
105
+ - **`minor`** label: Bumps the minor version (e.g., 1.2.3 → 1.3.0)
106
+ - **No label**: Defaults to patch bump (e.g., 1.2.3 → 1.2.4)
107
+
108
+ The workflow automatically:
109
+ 1. Detects the bump type from PR labels
110
+ 2. Updates the version in `lib/rspec_kung_fu_hamster/version.rb`
111
+ 3. Commits the version bump with message `[skip ci]`
112
+ 4. Creates and pushes a git tag (e.g., `v1.2.3`)
113
+
114
+ ### Manual Version Bumping
115
+
116
+ You can also manually bump the version using the script:
117
+
118
+ ```bash
119
+ ruby scripts/bump_version.rb [major|minor|patch]
120
+ ```
@@ -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
@@ -0,0 +1,117 @@
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
@@ -0,0 +1,3 @@
1
+ module RspecKungFuHamster
2
+ VERSION = '0.3.0'
3
+ end
@@ -1,112 +1,3 @@
1
- require 'rspec'
2
- require 'rspec/core/formatters/base_text_formatter'
3
-
4
- rspec_bin = $0.split('/').last
5
-
6
- class RspecKungFuHamster < RSpec::Core::Formatters::BaseTextFormatter
7
- RSpec::Core::Formatters.register self,
8
- # :start,
9
- # :example_start
10
- # :message,
11
- :example_passed,
12
- :example_pending,
13
- :example_failed
14
- # :dump_failures
15
-
16
- def initialize(output)
17
- @index = 0
18
- @example_passed = 0
19
- @example_pending = 0
20
- @example_failed = 0
21
- super(output)
22
- end
23
-
24
- def color_positions(length)
25
- total = @example_passed + @example_pending + @example_failed
26
- passed_percent = @example_passed * length / total
27
- pending_percent = @example_pending * length / total
28
-
29
- [passed_percent, passed_percent + pending_percent, length]
30
- end
31
-
32
- GREEN = "\e[32m"
33
- YELLOW = "\e[33m"
34
- RED = "\e[31m"
35
- RESET = "\e[0m"
36
-
37
- def colorize(string)
38
- green, yellow, red = color_positions(string.length)
39
- GREEN + string[0...green] + YELLOW + string[green...yellow] + RED + string[yellow...red] + RESET
40
- end
41
-
42
- def display(strings)
43
- colorize(strings.join("\n"))
44
- end
45
-
46
- def output_hamster
47
- output.puts "\e[2J\e[;H" + display(hamster_and_next)
48
- end
49
- def example_passed(notification)
50
- @example_passed += 1
51
- output_hamster
52
- end
53
- def example_pending(notification)
54
- @example_pending += 1
55
- output_hamster
56
- end
57
- def example_failed(notification)
58
- @example_failed += 1
59
- output_hamster
60
- end
61
-
62
- def hamster_and_next
63
- KUNG_FU_HAMSTER[@index % KUNG_FU_HAMSTER.length].tap { @index += 1 }
64
- end
65
-
66
- KUNG_FU_HAMSTER = [
67
- [
68
- " ()__() ",
69
- " / o o\\ | ",
70
- " |' =Y=';-| ",
71
- " { \\ / } ",
72
- " mmm mmm "
73
- ],[
74
- " ()__() ",
75
- " / o o\\ ; ",
76
- " |' =Y=';-/ ",
77
- " { \\ / } ",
78
- " mmm mmm "
79
- ],[
80
- " ()__() ",
81
- " / o o\\ ",
82
- " |' =Y=';----",
83
- " { \\ / } ",
84
- " mmm mmm "
85
- ],[
86
- " ()__() ",
87
- " / o o\\ ",
88
- " |' =Y=';-\\ ",
89
- " { \\ / } \\ ",
90
- " mmm mmm "
91
- ],[
92
- " ()__() ",
93
- " / o o\\ ",
94
- " |' =Y=';----",
95
- " { \\ / } ",
96
- " mmm mmm "
97
- ],[
98
- " ()__() ",
99
- " / o o\\ \\ ",
100
- " |' =Y=';-\\ ",
101
- " { \\ / } ",
102
- " mmm mmm "
103
- ]]
104
-
105
- DEAD_HAMSTER = [
106
- " ()__() ",
107
- " / X X\\ | ",
108
- " |' =Y=';-| ",
109
- " { \\ / } ",
110
- " mmm mmm "
111
- ]
112
- end
1
+ require 'rspec_kung_fu_hamster/version'
2
+ require 'rspec_kung_fu_hamster/formatter'
3
+ require 'rspec_kung_fu_hamster/detailed_formatter'
@@ -1,7 +1,7 @@
1
1
  require_relative '../lib/rspec_kung_fu_hamster.rb'
2
- describe RspecKungFuHamster do
2
+ describe RspecKungFuHamster::Formatter do
3
3
  100.times do |i|
4
4
  it { expect(i).to eq i }
5
5
  end
6
- it { expect(RspecKungFuHamster::KUNG_FU_HAMSTER.length).to eq 6 }
6
+ it { expect(RspecKungFuHamster::Formatter::KUNG_FU_HAMSTER.length).to eq 6 }
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-kungfuhamster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Powell
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rspec
@@ -30,18 +29,20 @@ email:
30
29
  executables: []
31
30
  extensions: []
32
31
  extra_rdoc_files:
33
- - README.md
34
32
  - LICENSE
33
+ - README.md
35
34
  files:
36
35
  - LICENSE
37
36
  - README.md
38
37
  - lib/rspec_kung_fu_hamster.rb
38
+ - lib/rspec_kung_fu_hamster/detailed_formatter.rb
39
+ - lib/rspec_kung_fu_hamster/formatter.rb
40
+ - lib/rspec_kung_fu_hamster/version.rb
39
41
  - spec/kungfuhamster_spec.rb
40
42
  homepage: https://github.com/stringsn88keys/rspec-kungfuhamster
41
43
  licenses:
42
44
  - MIT
43
45
  metadata: {}
44
- post_install_message:
45
46
  rdoc_options:
46
47
  - "--charset"
47
48
  - UTF-8
@@ -58,11 +59,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
59
  - !ruby/object:Gem::Version
59
60
  version: '0'
60
61
  requirements: []
61
- rubyforge_project:
62
- rubygems_version: 2.2.2
63
- signing_key:
62
+ rubygems_version: 3.6.9
64
63
  specification_version: 4
65
64
  summary: Rspec kung fu hamster formatter
66
65
  test_files:
67
66
  - spec/kungfuhamster_spec.rb
68
- has_rdoc: