Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form matcher's failure message unexpected behaviour #24

Open
ADodulad opened this issue May 21, 2019 · 1 comment
Open

Form matcher's failure message unexpected behaviour #24

ADodulad opened this issue May 21, 2019 · 1 comment

Comments

@ADodulad
Copy link
Contributor

Ok, I would actually address 3 issues here but since they all related to the same method they might have a single solution.

First

Each matcher includes following code:
failure_message { |actual| "expect #{form.inspect} (#{attributes}) to have #{method} method param" }
Anytime any of the matchers fails I receive the following error:

Failure/Error: it { expect(view.form).to have_form_field(node: "input", type: "password") }
   FrozenError: can't modify frozen String

This error comes from the #{form.inspect} operation when RSpec generates failure message and originates in haml's inspect method (which calls gsub! with a frozen string option enabled).

I was not able to reproduce this error using rspec-hanami repo and haml though. However I'm sure I'm just missing out something that happens under Hanami's hood.

Second

Whenever form matcher fail failure_message would output multi page diff of a FormBuilder object which is overkill.

Third

have_field matcher's failure_message includes errors. Look at that, there is no #{form.inspect}, #{attributes} or #{method} defined within matcher. Obviously that's must be a copy-paste issue from 'have_method' matcher.

matcher :have_field do |params|
  require 'hanami/utils/hash'
  attr_reader :form, :form_data, :params

  description { "have field with params" }
  match do |form|
    @form = form
    @params = ::Hanami::Utils::Hash.new(params).symbolize!
    @form_data = RSpec::Hanami::FormParser.new.call(form.to_s)

    form_data.any? do |input|
      input.merge(params) == params.merge(input)
    end
  end

  failure_message { |actual| "expect #{form.inspect} (#{attributes}) to have #{method} method param" }
  diffable
end

Solution

So as I mentioned one approach might handle all three issues:

  1. Output @form_data = RSpec::Hanami::FormParser.new.call(form.to_s) instead of '#{form.inspect}' in `failure_message' of every matcher.
  2. Remove diffable for every form matcher.
  3. Fix have_field matcher's failure_message with params.
@ADodulad
Copy link
Contributor Author

PR #25 as a proposal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant