0

The following is a Rails model test:

it "will respond to name" do
  @user.must_respond_to :name
end

In minitest, is there a way to shorten this syntax like this?

it { must_respond_to :name }

or even this?

it { must_respond_to (:name) }
Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Brent Eicher
  • 1,050
  • 9
  • 14

2 Answers2

0

I don't know if it is recommended to do that, but maybe you can just do this:

alias :old_it :it
def it test_name = "", ≺ old_it(test_name){@user.instance_eval(&pr)} end
sawa
  • 165,429
  • 45
  • 277
  • 381
0

The syntax you are looking for us not possible with the assertions and expectations as defined by methods in minitest. What you want is matchers. Take a look at the minitest-matchers project which enables the syntax you are after.

https://github.com/wojtekmach/minitest-matchers

blowmage
  • 8,854
  • 2
  • 35
  • 40