Module: MiniTest::Spec::Magic::Expectations::ClassMethods

Defined in:
lib/minitest/spec/magic/expectations.rb

Instance Method Summary collapse

Instance Method Details

#should(expectation, &block) ⇒ Object

Accepts either a matcher or a message with a block. Example:

class UserTest < ActiveSupport::TestCase

  should validate_presesence_of(:email)

  should "be valid" do
    subject.must_be :valid?
  end

end

Parameters:

  • expectation (Matcher|String)

    either a matcher or a message



46
47
48
49
50
51
52
53
54
# File 'lib/minitest/spec/magic/expectations.rb', line 46

def should(expectation, &block)
  message = if expectation.respond_to?(:description)
    block = lambda { should expectation }
    expectation.description
  else
    expectation
  end
  it "should #{message}", &block
end

#should_not(matcher) ⇒ Object

Parameters:

  • matcher (Matcher)

    a matcher



57
58
59
60
# File 'lib/minitest/spec/magic/expectations.rb', line 57

def should_not(matcher)
  block = lambda { should_not matcher }
  it "should not #{matcher.description}", &block
end