Class: RailsErrorDashboard::Services::RspecGenerator
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Services::RspecGenerator
- Defined in:
- lib/rails_error_dashboard/services/rspec_generator.rb
Overview
Pure algorithm: Assemble an RSpec request spec from an error log’s request data
Operates on data already stored in ErrorLog — zero runtime cost. Called at display time only.
Constant Summary collapse
- BODY_METHODS =
%w[ POST PUT PATCH DELETE ].freeze
Class Method Summary collapse
-
.call(error) ⇒ String
RSpec request spec string, or “” if insufficient data.
Instance Method Summary collapse
- #generate ⇒ String
-
#initialize(error) ⇒ RspecGenerator
constructor
A new instance of RspecGenerator.
Constructor Details
#initialize(error) ⇒ RspecGenerator
Returns a new instance of RspecGenerator.
24 25 26 |
# File 'lib/rails_error_dashboard/services/rspec_generator.rb', line 24 def initialize(error) @error = error end |
Class Method Details
.call(error) ⇒ String
Returns RSpec request spec string, or “” if insufficient data.
18 19 20 21 22 |
# File 'lib/rails_error_dashboard/services/rspec_generator.rb', line 18 def self.call(error) new(error).generate rescue => e "" end |
Instance Method Details
#generate ⇒ String
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rails_error_dashboard/services/rspec_generator.rb', line 29 def generate path = request_path return "" if path.blank? method = http_method lines = [] lines << header_lines(method, path) lines << "" lines << " it \"reproduces the error\" do" lines << request_line(method, path) lines << "" lines << " # Original error: #{error_type}" lines << " # Expect the response to indicate the error" lines << " expect(response).to have_http_status(:internal_server_error)" lines << " end" lines << "end" lines.join("\n") rescue => e "" end |