turnip_documentation_formatter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0a0eaf35ce8b914fe9c8d2db2777289852d8e65044e1809f0e133893b4ebc59b
4
+ data.tar.gz: 39e741e3ccd7c5072787aa03962a832f26b8d9e3117ab5005368791a5f159f8a
5
+ SHA512:
6
+ metadata.gz: eceea9cb12aef29e5f32a5b7d07476b18d00ea3ca3c457f9ce950d2da42cd12005f7eb44bf359b889d7507b39de77ab6ed7ac711d50f8b76a85de283706659f3
7
+ data.tar.gz: 2bd911181bb49e1549583fd70eddde784120ce407658c75cb885674c4fbe6b266e1558e9a8236c846eac40384af6ef21419e4ca47dde83cf1446a55e12772784
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --require turnip/rspec
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in turnip-documentation-formatter.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ turnip_documentation_formatter (0.0.1)
5
+ turnip (~> 4.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.1.4.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ zeitwerk (~> 2.3)
16
+ concurrent-ruby (1.1.9)
17
+ cucumber-gherkin (14.2.0)
18
+ cucumber-messages (~> 12.4, >= 12.4.0)
19
+ cucumber-messages (12.4.0)
20
+ protobuf-cucumber (~> 3.10, >= 3.10.8)
21
+ diff-lcs (1.4.4)
22
+ i18n (1.8.11)
23
+ concurrent-ruby (~> 1.0)
24
+ middleware (0.1.0)
25
+ minitest (5.14.4)
26
+ protobuf-cucumber (3.10.8)
27
+ activesupport (>= 3.2)
28
+ middleware
29
+ thor
30
+ thread_safe
31
+ rake (13.0.6)
32
+ rspec (3.10.0)
33
+ rspec-core (~> 3.10.0)
34
+ rspec-expectations (~> 3.10.0)
35
+ rspec-mocks (~> 3.10.0)
36
+ rspec-core (3.10.1)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-expectations (3.10.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-mocks (3.10.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-support (3.10.3)
45
+ thor (1.1.0)
46
+ thread_safe (0.3.6)
47
+ turnip (4.3.0)
48
+ cucumber-gherkin (~> 14.0)
49
+ rspec (>= 3.0, < 4.0)
50
+ tzinfo (2.0.4)
51
+ concurrent-ruby (~> 1.0)
52
+ zeitwerk (2.5.1)
53
+
54
+ PLATFORMS
55
+ x86_64-linux
56
+
57
+ DEPENDENCIES
58
+ rake (~> 13.0)
59
+ rspec (~> 3.0)
60
+ turnip_documentation_formatter!
61
+
62
+ BUNDLED WITH
63
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Aram Visser
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Turnip Documentation Formatter
2
+
3
+ This gem extends the default RSpec documentation formatter for [Turnip](https://github.com/jnicklas/turnip) to print each step on it's own line.
4
+
5
+ This makes it easier to see on exactly which step an error occured.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'turnip_documentation_formatter'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install turnip_documentation_formatter
22
+
23
+ ## Usage
24
+
25
+ Use the default documentation formatter when running RSpec (`rspec --format documentation`).
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/turnip-documentation-formatter.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: %i[spec]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "turnip/documentation_formatter"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ Feature: Documentation formatter examples
2
+ Scenario: Passing
3
+ Given there is a monster
4
+ When I attack it
5
+ Then it should die
6
+
7
+ Scenario: Error
8
+ Given there is a monster
9
+ When I attack it
10
+ And raise error
11
+ Then it should die
12
+
13
+ Scenario: Pending
14
+ Given there is a monster
15
+ When I attack it
16
+ And do something unexpected
17
+ Then it should die
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turnip::RSpec
4
+ module Execute
5
+ def run_step(feature_file, step)
6
+ reporter = ::RSpec.current_example.reporter
7
+ reporter.publish(:step_started, { step: step })
8
+
9
+ begin
10
+ instance_eval <<-EOS, feature_file, step.line
11
+ step(step)
12
+ EOS
13
+ rescue Turnip::Pending => e
14
+ reporter.publish(:step_pending, { step: step })
15
+
16
+ example = ::RSpec.current_example
17
+ example.metadata[:line_number] = step.line
18
+ example.metadata[:location] = "#{example.metadata[:file_path]}:#{step.line}"
19
+
20
+ if ::RSpec.configuration.raise_error_for_unimplemented_steps
21
+ e.backtrace.push "#{feature_file}:#{step.line}:in `#{step.description}'"
22
+ raise
23
+ end
24
+
25
+ skip("No such step: '#{e}'")
26
+ rescue StandardError, ::RSpec::Expectations::ExpectationNotMetError => e
27
+ reporter.publish(:step_failed, { step: step })
28
+
29
+ e.backtrace.push "#{feature_file}:#{step.line}:in `#{step.description}'"
30
+ raise e
31
+ end
32
+
33
+ reporter.publish(:step_passed, { step: step })
34
+ end
35
+ end
36
+
37
+ class << self
38
+ def run(feature_file)
39
+ feature = Turnip::Builder.build(feature_file)
40
+
41
+ return nil if feature.nil?
42
+
43
+ instance_eval <<-EOS, feature_file, feature.line
44
+ context = ::RSpec.describe feature.name, feature.metadata_hash
45
+ run_scenario_group(context, feature, feature_file)
46
+ EOS
47
+ end
48
+
49
+ private
50
+
51
+ #
52
+ # @param [RSpec::ExampleGroups] context
53
+ # @param [Turnip::Node::Feature|Turnip::Node::Rule] group
54
+ # @param [String] filename
55
+ #
56
+ def run_scenario_group(context, group, filename)
57
+ background_steps = group.backgrounds.map(&:steps).flatten
58
+
59
+ context.before do
60
+ background_steps.each do |step|
61
+ run_step(filename, step)
62
+ end
63
+ end
64
+
65
+ group.scenarios.each do |scenario|
66
+ all_steps = background_steps + scenario.steps
67
+ description = all_steps.map(&:to_s).join(' -> ')
68
+ metadata = scenario.metadata_hash.merge(turnip_steps: all_steps)
69
+
70
+ context.describe scenario.name, metadata do
71
+ instance_eval <<-EOS, filename, scenario.line
72
+ it description do
73
+ scenario.steps.each do |step|
74
+ run_step(filename, step)
75
+ end
76
+ end
77
+ EOS
78
+ end
79
+ end
80
+
81
+ if group.is_a?(Turnip::Node::Feature)
82
+ group.rules.each do |rule|
83
+ rule_context = context.context(rule.name, { turnip: true })
84
+ run_scenario_group(rule_context, rule, filename)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turnip
4
+ module DocumentationFormatter
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec'
4
+ require 'turnip'
5
+ require 'turnip/rspec'
6
+
7
+ require "turnip_documentation_formatter/turnip_extension.rb"
8
+ require "turnip_documentation_formatter/version"
9
+
10
+ module Turnip
11
+ # Extensions for the RSpec documentation formatter
12
+ module DocumentationFormatter
13
+ def initialize(output)
14
+ super
15
+
16
+ @current_step = nil
17
+ @remaining_scenario_steps = []
18
+ end
19
+
20
+ def example_started(notification)
21
+ super if defined?(super)
22
+
23
+ @remaining_scenario_steps = notification.example.metadata[:turnip_steps].dup
24
+ end
25
+
26
+ def step_started(notification)
27
+ @current_step = notification.step
28
+ @remaining_scenario_steps.shift
29
+ end
30
+
31
+ def step_passed(notification)
32
+ output.puts step_passed_output(notification.step)
33
+ end
34
+
35
+ def example_passed(passed)
36
+ return super unless turnip_example?(passed)
37
+
38
+ flush_messages if respond_to? :flush_messages
39
+ @example_running = false
40
+ end
41
+
42
+ def example_pending(pending)
43
+ return super unless turnip_example?(pending)
44
+
45
+ output.puts step_pending_output(@current_step,
46
+ pending.example.execution_result.pending_message)
47
+ output.puts remaining_step_names
48
+
49
+ flush_messages if respond_to? :flush_messages
50
+ @example_running = false
51
+ end
52
+
53
+ def example_failed(failure)
54
+ return super unless turnip_example?(failure)
55
+
56
+ failure.example.metadata[:failed_step] = @current_step
57
+ output.puts step_failed_output(@current_step)
58
+ output.puts remaining_step_names
59
+
60
+ flush_messages if respond_to? :flush_messages
61
+ @example_running = false
62
+ end
63
+
64
+ private
65
+
66
+ def turnip_example?(notification)
67
+ notification.example.metadata[:turnip]
68
+ end
69
+
70
+ def step_passed_output(step)
71
+ ::RSpec::Core::Formatters::ConsoleCodes.wrap("#{current_indentation}#{step}",
72
+ :success)
73
+ end
74
+
75
+ def step_pending_output(step, message)
76
+ ::RSpec::Core::Formatters::ConsoleCodes.wrap("#{current_indentation}#{step} " \
77
+ "(PENDING: #{message})",
78
+ :pending)
79
+ end
80
+
81
+ def step_failed_output(step)
82
+ ::RSpec::Core::Formatters::ConsoleCodes.wrap("#{current_indentation}#{step} " \
83
+ "(FAILED - #{next_failure_index})",
84
+ :failure)
85
+ end
86
+
87
+ def remaining_step_names
88
+ @remaining_scenario_steps.map do |step|
89
+ "#{current_indentation}#{step}"
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+
96
+ # Only extend documentation formatter if it's loaded
97
+ if defined?(::RSpec::Core)
98
+ # Extend the default documentation formatter
99
+ class RSpec::Core::Formatters::DocumentationFormatter
100
+ RSpec::Core::Formatters.register self, :example_started, :example_group_started, :example_group_finished,
101
+ :example_passed, :example_pending, :example_failed, :step_started, :step_passed
102
+
103
+
104
+ prepend Turnip::DocumentationFormatter
105
+ end
106
+
107
+ # Make sure the documentation formatter listens for turnip events if it's already registered
108
+ RSpec.world.reporter.registered_listeners(:example_started).each do |formatter|
109
+ if formatter.is_a? RSpec::Core::Formatters::DocumentationFormatter
110
+ RSpec.world.reporter.register_listener formatter, :step_started, :step_passed
111
+ end
112
+ end
113
+
114
+ # Highlight error step in summary description
115
+ class RSpec::Core::Formatters::ExceptionPresenter
116
+ def encoded_description(description)
117
+ return if description.nil?
118
+
119
+ if example.metadata[:turnip] && example.metadata[:failed_step]
120
+ step = example.metadata[:failed_step].to_s
121
+ error = ::RSpec::Core::Formatters::ConsoleCodes.wrap(step, :failure)
122
+ description = description.gsub(step, error)
123
+ end
124
+
125
+ encoded_string(description)
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/turnip_documentation_formatter/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "turnip_documentation_formatter"
7
+ spec.version = Turnip::DocumentationFormatter::VERSION
8
+ spec.authors = ["Aram Visser"]
9
+ spec.email = ["hello@aramvisser.com"]
10
+
11
+ spec.summary = "RSpec documentation formatter for Turnip"
12
+ spec.description = "Show each turnip step on it's own line when using the documentation formatter (`rspec -fd`)"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+
16
+ spec.metadata["source_code_uri"] = "https://github.com/aramvisser/turnip_documentation_formatter"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_runtime_dependency "turnip", "~> 4.3"
28
+ spec.add_runtime_dependency "rspec", "~> 3.10"
29
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turnip_documentation_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aram Visser
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: turnip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.10'
41
+ description: Show each turnip step on it's own line when using the documentation formatter
42
+ (`rspec -fd`)
43
+ email:
44
+ - hello@aramvisser.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - examples/documentation_formatter.feature
59
+ - lib/turnip_documentation_formatter.rb
60
+ - lib/turnip_documentation_formatter/turnip_extension.rb
61
+ - lib/turnip_documentation_formatter/version.rb
62
+ - turnip-documentation-formatter.gemspec
63
+ homepage:
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ source_code_uri: https://github.com/aramvisser/turnip_documentation_formatter
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.4.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.2.15
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: RSpec documentation formatter for Turnip
87
+ test_files: []