Extended maintenance of Ruby versions 1.8.7 and 1.9.2 will end on July 31, 2014. Read more

In Files

  • minitest/spec.rb

Class/Module Index [+]

Quicksearch

MiniTest::Spec

Public Class Methods

after(type = :each, &block) click to toggle source

Define an ‘after’ action. Inherits the way normal methods should.

NOTE: type is ignored and is only there to make porting easier.

Equivalent to MiniTest::Unit::TestCase#teardown.

 
               # File minitest/spec.rb, line 148
def self.after type = :each, &block
  raise "unsupported after type: #{type}" unless type == :each
  define_inheritable_method :teardown, &block
end
            
before(type = :each, &block) click to toggle source

Define a ‘before’ action. Inherits the way normal methods should.

NOTE: type is ignored and is only there to make porting easier.

Equivalent to MiniTest::Unit::TestCase#setup.

 
               # File minitest/spec.rb, line 136
def self.before type = :each, &block
  raise "unsupported before type: #{type}" unless type == :each
  define_inheritable_method :setup, &block
end
            
it(desc, &block) click to toggle source

Define an expectation with name desc. Name gets morphed to a proper test method name. For some freakish reason, people who write specs don’t like class inheritence, so this goes way out of its way to make sure that expectations aren’t inherited.

Hint: If you do want inheritence, use minitest/unit. You can mix and match between assertions and expectations as much as you want.

 
               # File minitest/spec.rb, line 162
def self.it desc, &block
  block ||= proc { skip "(no tests defined)" }

  @specs ||= 0
  @specs += 1

  name = "test_%04d_%s" % [ @specs, desc.gsub(/\W+/, '_').downcase ]

  define_method name, &block

  classes(MiniTest::Spec).each do |mod|
    mod.send :undef_method, name if mod.respond_to? name
  end
end
            

Public Instance Methods

must_be click to toggle source

See MiniTest::Assertions#assert

 
               # File minitest/spec.rb, line 181
  
            
must_be_close_to click to toggle source

See MiniTest::Assertions#assert_in_delta

 
               # File minitest/spec.rb, line 185
  
            
must_be_empty click to toggle source

See MiniTest::Assertions#assert_empty

 
               # File minitest/spec.rb, line 189
  
            
must_be_instance_of click to toggle source

See MiniTest::Assertions#assert_instance_of

 
               # File minitest/spec.rb, line 193
  
            
must_be_kind_of click to toggle source

See MiniTest::Assertions#assert_kind_of

 
               # File minitest/spec.rb, line 197
  
            
must_be_nil click to toggle source

See MiniTest::Assertions#assert_nil

 
               # File minitest/spec.rb, line 201
  
            
must_be_same_as click to toggle source

See MiniTest::Assertions#assert_same

 
               # File minitest/spec.rb, line 205
  
            
must_be_within_delta click to toggle source

See MiniTest::Assertions#assert_in_delta

 
               # File minitest/spec.rb, line 209
  
            
must_be_within_epsilon click to toggle source

See MiniTest::Assertions#assert_in_epsilon

 
               # File minitest/spec.rb, line 213
  
            
must_equal click to toggle source

See MiniTest::Assertions#assert_equal

 
               # File minitest/spec.rb, line 217
  
            
must_include click to toggle source

See MiniTest::Assertions#assert_includes

 
               # File minitest/spec.rb, line 221
  
            
must_match click to toggle source

See MiniTest::Assertions#assert_match

 
               # File minitest/spec.rb, line 225
  
            
must_raise click to toggle source

See MiniTest::Assertions#assert_raises

 
               # File minitest/spec.rb, line 229
  
            
must_respond_to click to toggle source

See MiniTest::Assertions#assert_respond_to

 
               # File minitest/spec.rb, line 233
  
            
must_send click to toggle source

See MiniTest::Assertions#assert_send

 
               # File minitest/spec.rb, line 237
  
            
must_throw click to toggle source

See MiniTest::Assertions#assert_throw

 
               # File minitest/spec.rb, line 241
  
            
wont_be click to toggle source

See MiniTest::Assertions#refute

 
               # File minitest/spec.rb, line 245
  
            
wont_be_close_to click to toggle source

See MiniTest::Assertions#refute_in_delta

 
               # File minitest/spec.rb, line 249
  
            
wont_be_empty click to toggle source

See MiniTest::Assertions#refute_empty

 
               # File minitest/spec.rb, line 253
  
            
wont_be_instance_of click to toggle source

See MiniTest::Assertions#refute_instance_of

 
               # File minitest/spec.rb, line 257
  
            
wont_be_kind_of click to toggle source

See MiniTest::Assertions#refute_kind_of

 
               # File minitest/spec.rb, line 261
  
            
wont_be_nil click to toggle source

See MiniTest::Assertions#refute_nil

 
               # File minitest/spec.rb, line 265
  
            
wont_be_same_as click to toggle source

See MiniTest::Assertions#refute_same

 
               # File minitest/spec.rb, line 269
  
            
wont_be_within_delta click to toggle source

See MiniTest::Assertions#refute_in_delta

 
               # File minitest/spec.rb, line 273
  
            
wont_be_within_epsilon click to toggle source

See MiniTest::Assertions#refute_in_epsilon

 
               # File minitest/spec.rb, line 277
  
            
wont_equal click to toggle source

See MiniTest::Assertions#refute_equal

 
               # File minitest/spec.rb, line 281
  
            
wont_include click to toggle source

See MiniTest::Assertions#refute_includes

 
               # File minitest/spec.rb, line 285
  
            
wont_match click to toggle source

See MiniTest::Assertions#refute_match

 
               # File minitest/spec.rb, line 289
  
            
wont_respond_to click to toggle source

See MiniTest::Assertions#refute_respond_to

 
               # File minitest/spec.rb, line 292

            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus