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

Minitest::Assertions::AssertRequiresInitializeParameter does not properly validate parameters. #74

Open
jdickey opened this issue Jul 22, 2016 · 0 comments
Assignees
Labels
Milestone

Comments

@jdickey
Copy link
Contributor

jdickey commented Jul 22, 2016

It's bad when code to support your testing has bugs that give an unearned green bar when you invoke them with a typo.

Such is the case with the current MiniTest::Assertions::AssertRequiresInitializeParameter asserter class which we use to verify that a class requires specific named parameters to its #initialise method.

Given a class

class Foo
  def initialise(foo:, bar:)
    # ...
  end
  # ...
end

we can write a MiniTest::Spec assertion such as

  # ...
  let(:params) { { foo: foo, bar: bar } }
  # ...
  it 'requires a :bar parameter for initialisation' do
    expect(Foo).must_require_initialize_parameter params, :bar
  end

and get a legitimate green bar.

Writing the test with a typo, such as

  # ...
  let(:params) { { foo: foo, bar: bar } }
  # ...
  it 'requires a :bar parameter for initialisation' do
    expect(Foo).must_require_initialize_parameter params, :bear
  end

will give an illegitimate green bar; the asserter deletes the entry specified by the second parameter from (a copy of) the Hash specified by the first, and attempts to instantiate the class with the result. In the code as of Commit 376ca33, deleting the nonexistent key silently has no effect, and the instantiation, receiving valid parameters, succeeds.

The implementation extracted to the new prolog_minitest_matchers Gem solves this (and therefore conflicts with the current implementation in this Gem). The prolog-use_cases implementation should be removed and the prolog_minitest_matchers Gem added as a development dependency instead.

@jdickey jdickey added the bug label Jul 22, 2016
@jdickey jdickey added this to the Gem Release 0.13.0 milestone Jul 22, 2016
@jdickey jdickey self-assigned this Jul 22, 2016
@jdickey jdickey modified the milestones: Meldd 0.5, Gem Release 0.13.0 Aug 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant