Skip to content

Commit

Permalink
Write use of method_missing in page objects to file
Browse files Browse the repository at this point in the history
Instead of filling stdout with messages about these missing page object method calls, log them in a file per RSpec suite run.
  • Loading branch information
steventux committed May 29, 2024
1 parent 23eba39 commit 7057fa3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
config.include Capybara::RSpecMatchers, type: :component
config.include Rails.application.routes.url_helpers

config.add_setting :methods_missing_reporter
methods_missing_reporter = RSpec::Core::Reporter.new(config)
formatter = RSpec::Core::Formatters::BaseTextFormatter.new(File.open("tmp/rspec-magic-page-object-methods.txt", "wb"))
methods_missing_reporter.register_listener(formatter, "message")
config.methods_missing_reporter = methods_missing_reporter

config.before(:each, exceptions_app: true) do
# Make the app behave how it does in non dev/test environments and use the
# ErrorsController via config.exceptions_app = routes in config/application.rb
Expand Down
9 changes: 6 additions & 3 deletions spec/support/features/steps/generic_page_object_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ def method_missing(method_symbol, *query_values)
page_object = page_object.new
end

puts "Called non-existing method #{method_symbol}"
puts "Call was re-rerouted to #{page_object_name.camelize}##{method_name} with query_params: #{query_params}, query_values: #{query_values}"
puts "Please create your own method, we are planning to delete this helper"
RSpec.configuration.methods_missing_reporter&.message([
"Missing method: #{method_symbol}",
"Generic call: #{page_object_name.camelize}##{method_name}",
"Query params: #{query_params}",
"Query values: #{query_values}",
].join(", "))

generic_call page_object, method_name, query_params, query_values
end
Expand Down

0 comments on commit 7057fa3

Please sign in to comment.