Class: Browsable::Drivers::RSpec
- Inherits:
-
Object
- Object
- Browsable::Drivers::RSpec
- Defined in:
- lib/browsable/drivers/rspec.rb
Overview
The RSpec driver — activated by ‘require “browsable/rspec”`.
On load it (a) verifies a Rails app is reachable, (b) inserts the runtime middleware idempotently, and © registers before(:suite) / after(:suite) hooks so the audit log is cleared and the report rendered automatically without per-spec boilerplate.
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- DEFAULTS =
{ fail_on: :error, # :error | :warning | :never format: :human, # :human | :json | :github output: :stdout, # :stdout | :stderr | "path/to/file" enabled: true }.freeze
Class Method Summary collapse
- .after_suite ⇒ Object
- .before_suite ⇒ Object
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .emit(report) ⇒ Object
-
.install! ⇒ Object
Wire the middleware and RSpec hooks.
-
.rails_application ⇒ Object
The Rails app whose middleware stack we mutate.
- .reset! ⇒ Object
Class Method Details
.after_suite ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/browsable/drivers/rspec.rb', line 95 def after_suite return unless configuration.enabled return if Browsable.audit_log.empty? report = Browsable::TestReport.new emit(report) report.fail_suite_if_errors!(fail_on: configuration.fail_on) unless configuration.fail_on == :never end |
.before_suite ⇒ Object
91 92 93 |
# File 'lib/browsable/drivers/rspec.rb', line 91 def before_suite Browsable.audit_log.clear end |
.configuration ⇒ Object
28 29 30 |
# File 'lib/browsable/drivers/rspec.rb', line 28 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
32 33 34 |
# File 'lib/browsable/drivers/rspec.rb', line 32 def configure yield configuration end |
.emit(report) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/browsable/drivers/rspec.rb', line 104 def emit(report) rendered = report.render(format: configuration.format) target = configuration.output case target when :stdout then $stdout.puts(rendered) when :stderr then $stderr.puts(rendered) when IO, StringIO then target.puts(rendered) else File.write(target.to_s, rendered) end end |
.install! ⇒ Object
Wire the middleware and RSpec hooks. Called once when the entry-point file is required.
42 43 44 45 46 47 |
# File 'lib/browsable/drivers/rspec.rb', line 42 def install! require "rspec/core" ensure_rails! insert_middleware register_hooks end |
.rails_application ⇒ Object
The Rails app whose middleware stack we mutate. Extracted so tests can stub the lookup.
51 52 53 54 55 |
# File 'lib/browsable/drivers/rspec.rb', line 51 def rails_application return nil unless defined?(::Rails) ::Rails.application end |
.reset! ⇒ Object
36 37 38 |
# File 'lib/browsable/drivers/rspec.rb', line 36 def reset! @configuration = nil end |