Giter VIP home page Giter VIP logo

minitest's Introduction

minitest/{test,spec,mock,benchmark}

home

github.com/minitest/minitest

bugs

github.com/minitest/minitest/issues

rdoc

docs.seattlerb.org/minitest

clog

github.com/minitest/minitest/blob/master/History.rdoc

vim

github.com/sunaku/vim-ruby-minitest

emacs

github.com/arthurnn/minitest-emacs

DESCRIPTION:

minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.

"I had a class with Jim Weirich on testing last week and we were
 allowed to choose our testing frameworks. Kirk Haines and I were
 paired up and we cracked open the code for a few test
 frameworks...

 I MUST say that minitest is *very* readable / understandable
 compared to the 'other two' options we looked at. Nicely done and
 thank you for helping us keep our mental sanity."

-- Wayne E. Seguin

minitest/test is a small and incredibly fast unit testing framework. It provides a rich set of assertions to make your tests clean and readable.

minitest/spec is a functionally complete spec engine. It hooks onto minitest/test and seamlessly bridges test assertions over to spec expectations.

minitest/benchmark is an awesome way to assert the performance of your algorithms in a repeatable manner. Now you can assert that your newb co-worker doesn’t replace your linear algorithm with an exponential one!

minitest/mock by Steven Baker, is a beautifully tiny mock (and stub) object framework.

minitest/pride shows pride in testing and adds coloring to your test output. I guess it is an example of how to write IO pipes too. :P

minitest/test is meant to have a clean implementation for language implementors that need a minimal set of methods to bootstrap a working test suite. For example, there is no magic involved for test-case discovery.

"Again, I can't praise enough the idea of a testing/specing
 framework that I can actually read in full in one sitting!"

-- Piotr Szotkowski

Comparing to rspec:

rspec is a testing DSL. minitest is ruby.

-- Adam Hawkins, "Bow Before MiniTest"

minitest doesn’t reinvent anything that ruby already provides, like: classes, modules, inheritance, methods. This means you only have to learn ruby to use minitest and all of your regular OO practices like extract-method refactorings still apply.

FEATURES/PROBLEMS:

  • minitest/autorun - the easy and explicit way to run all your tests.

  • minitest/test - a very fast, simple, and clean test system.

  • minitest/spec - a very fast, simple, and clean spec system.

  • minitest/mock - a simple and clean mock/stub system.

  • minitest/benchmark - an awesome way to assert your algorithm’s performance.

  • minitest/pride - show your pride in testing!

  • minitest/test_task - a full-featured and clean rake task generator.

  • Incredibly small and fast runner, but no bells and whistles.

  • Written by squishy human beings. Software can never be perfect. We will all eventually die.

RATIONALE:

See design_rationale.rb to see how specs and tests work in minitest.

SYNOPSIS:

Given that you’d like to test the following class:

class Meme
  def i_can_has_cheezburger?
    "OHAI!"
  end

  def will_it_blend?
    "YES!"
  end
end

Unit tests

Define your tests as methods beginning with test_.

require "minitest/autorun"

class TestMeme < Minitest::Test
  def setup
    @meme = Meme.new
  end

  def test_that_kitty_can_eat
    assert_equal "OHAI!", @meme.i_can_has_cheezburger?
  end

  def test_that_it_will_not_blend
    refute_match /^no/i, @meme.will_it_blend?
  end

  def test_that_will_be_skipped
    skip "test this later"
  end
end

Specs

require "minitest/autorun"

describe Meme do
  before do
    @meme = Meme.new
  end

  describe "when asked about cheeseburgers" do
    it "must respond positively" do
      _(@meme.i_can_has_cheezburger?).must_equal "OHAI!"
    end
  end

  describe "when asked about blending possibilities" do
    it "won't say no" do
      _(@meme.will_it_blend?).wont_match /^no/i
    end
  end
end

For matchers support check out:

Benchmarks

Add benchmarks to your tests.

# optionally run benchmarks, good for CI-only work!
require "minitest/benchmark" if ENV["BENCH"]

class TestMeme < Minitest::Benchmark
  # Override self.bench_range or default range is [1, 10, 100, 1_000, 10_000]
  def bench_my_algorithm
    assert_performance_linear 0.9999 do |n| # n is a range value
      @obj.my_algorithm(n)
    end
  end
end

Or add them to your specs. If you make benchmarks optional, you’ll need to wrap your benchmarks in a conditional since the methods won’t be defined. In minitest 5, the describe name needs to match /Bench(mark)?$/.

describe "Meme Benchmark" do
  if ENV["BENCH"] then
    bench_performance_linear "my_algorithm", 0.9999 do |n|
      100.times do
        @obj.my_algorithm(n)
      end
    end
  end
end

outputs something like:

# Running benchmarks:

TestBlah	100	1000	10000
bench_my_algorithm	 0.006167	 0.079279	 0.786993
bench_other_algorithm	 0.061679	 0.792797	 7.869932

Output is tab-delimited to make it easy to paste into a spreadsheet.

Mocks

Mocks and stubs defined using terminology by Fowler & Meszaros at www.martinfowler.com/bliki/TestDouble.html:

“Mocks are pre-programmed with expectations which form a specification of the calls they are expected to receive. They can throw an exception if they receive a call they don’t expect and are checked during verification to ensure they got all the calls they were expecting.”

class MemeAsker
  def initialize(meme)
    @meme = meme
  end

  def ask(question)
    method = question.tr(" ", "_") + "?"
    @meme.__send__(method)
  end
end

require "minitest/autorun"

describe MemeAsker, :ask do
  describe "when passed an unpunctuated question" do
    it "should invoke the appropriate predicate method on the meme" do
      @meme = Minitest::Mock.new
      @meme_asker = MemeAsker.new @meme
      @meme.expect :will_it_blend?, :return_value

      @meme_asker.ask "will it blend"

      @meme.verify
    end
  end
end

Multi-threading and Mocks

Minitest mocks do not support multi-threading. If it works, fine, if it doesn’t you can use regular ruby patterns and facilities like local variables. Here’s an example of asserting that code inside a thread is run:

def test_called_inside_thread
  called = false
  pr = Proc.new { called = true }
  thread = Thread.new(&pr)
  thread.join
  assert called, "proc not called"
end

Stubs

Mocks and stubs are defined using terminology by Fowler & Meszaros at www.martinfowler.com/bliki/TestDouble.html:

“Stubs provide canned answers to calls made during the test”.

Minitest’s stub method overrides a single method for the duration of the block.

def test_stale_eh
  obj_under_test = Something.new

  refute obj_under_test.stale?

  Time.stub :now, Time.at(0) do   # stub goes away once the block is done
    assert obj_under_test.stale?
  end
end

A note on stubbing: In order to stub a method, the method must actually exist prior to stubbing. Use a singleton method to create a new non-existing method:

def obj_under_test.fake_method
  ...
end

Running Your Tests

Ideally, you’ll use a rake task to run your tests (see below), either piecemeal or all at once. BUT! You don’t have to:

% ruby -Ilib:test test/minitest/test_minitest_test.rb
Run options: --seed 37685

# Running:

...................................................................... (etc)

Finished in 0.107130s, 1446.8403 runs/s, 2959.0217 assertions/s.

155 runs, 317 assertions, 0 failures, 0 errors, 0 skips

There are runtime options available, both from minitest itself, and also provided via plugins. To see them, simply run with --help:

% ruby -Ilib:test test/minitest/test_minitest_test.rb --help
minitest options:
    -h, --help                       Display this help.
    -s, --seed SEED                  Sets random seed. Also via env. Eg: SEED=n rake
    -v, --verbose                    Verbose. Show progress processing files.
    -n, --name PATTERN               Filter run on /regexp/ or string.
    -e, --exclude PATTERN            Exclude /regexp/ or string from run.

Known extensions: pride, autotest
    -p, --pride                      Pride. Show your testing pride!
    -a, --autotest                   Connect to autotest server.

Rake Tasks

You can set up a rake task to run all your tests by adding this to your Rakefile:

require "minitest/test_task"

Minitest::TestTask.create # named test, sensible defaults

# or more explicitly:

Minitest::TestTask.create(:test) do |t|
  t.libs << "test"
  t.libs << "lib"
  t.warning = false
  t.test_globs = ["test/**/*_test.rb"]
end

task :default => :test

Each of these will generate 4 tasks:

rake test          :: Run the test suite.
rake test:cmd      :: Print out the test command.
rake test:isolated :: Show which test files fail when run separately.
rake test:slow     :: Show bottom 25 tests sorted by time.

Rake Task Variables

There are a bunch of variables you can supply to rake to modify the run.

MT_LIB_EXTRAS :: Extra libs to dynamically override/inject for custom runs.
N             :: -n: Tests to run (string or /regexp/).
X             :: -x: Tests to exclude (string or /regexp/).
A             :: Any extra arguments. Honors shell quoting.
MT_CPU        :: How many threads to use for parallel test runs
SEED          :: -s --seed Sets random seed.
TESTOPTS      :: Deprecated, same as A
FILTER        :: Deprecated, same as A

Writing Extensions

To define a plugin, add a file named minitest/XXX_plugin.rb to your project/gem. That file must be discoverable via ruby’s LOAD_PATH (via rubygems or otherwise). Minitest will find and require that file using Gem.find_files. It will then try to call plugin_XXX_init during startup. The option processor will also try to call plugin_XXX_options passing the OptionParser instance and the current options hash. This lets you register your own command-line options. Here’s a totally bogus example:

# minitest/bogus_plugin.rb:

module Minitest
  def self.plugin_bogus_options(opts, options)
    opts.on "--myci", "Report results to my CI" do
      options[:myci] = true
      options[:myci_addr] = get_myci_addr
      options[:myci_port] = get_myci_port
    end
  end

  def self.plugin_bogus_init(options)
    self.reporter << MyCI.new(options) if options[:myci]
  end
end

Adding custom reporters

Minitest uses composite reporter to output test results using multiple reporter instances. You can add new reporters to the composite during the init_plugins phase. As we saw in plugin_bogus_init above, you simply add your reporter instance to the composite via <<.

AbstractReporter defines the API for reporters. You may subclass it and override any method you want to achieve your desired behavior.

start

Called when the run has started.

record

Called for each result, passed or otherwise.

report

Called at the end of the run.

passed?

Called to see if you detected any problems.

Using our example above, here is how we might implement MyCI:

# minitest/bogus_plugin.rb

module Minitest
  class MyCI < AbstractReporter
    attr_accessor :results, :addr, :port

    def initialize options
      self.results = []
      self.addr = options[:myci_addr]
      self.port = options[:myci_port]
    end

    def record result
      self.results << result
    end

    def report
      CI.connect(addr, port).send_results self.results
    end
  end

  # code from above...
end

FAQ

What versions are compatible with what? Or what versions are supported?

Minitest is a dependency of rails, which until fairly recently had an overzealous backwards compatibility policy. As such, I’m stuck supporting versions of ruby that are long past EOL. Hopefully I’ll be able to support only current versions of ruby sometime in the near future.

(As of 2023-03-05)

Current versions of rails: (endoflife.date/rails)

| rails | min ruby | rec ruby | minitest | status   |  EOL Date  |
|-------+----------+----------+----------+----------+------------|
|   7.0 | >= 2.7   |      3.1 | >= 5.1   | Current  | 2025-06-01?|
|   6.1 | >= 2.5   |      3.0 | >= 5.1   | Maint    | 2024-06-01?|
|   6.0 | >= 2.5   |      2.6 | >= 5.1   | Security | 2023-06-01 |
|   5.2 | >= 2.2.2 |      2.5 | ~> 5.1   | EOL      | 2022-06-01 |

If you want to look at the requirements for a specific version, run:

gem spec -r --ruby rails -v 7.0.0

Current versions of ruby: (endoflife.date/ruby)

| ruby | Status  |   EOL Date |
|------+---------+------------|
|  3.2 | Current | 2026-03-31 |
|  3.1 | Maint   | 2025-03-31 |
|  3.0 | Maint   | 2024-03-31 |
|  2.7 | Security| 2023-03-31 |
|  2.6 | EOL     | 2022-03-31 |
|  2.5 | EOL     | 2021-03-31 |

How to test SimpleDelegates?

The following implementation and test:

class Worker < SimpleDelegator
  def work
  end
end

describe Worker do
  before do
    @worker = Worker.new(Object.new)
  end

  it "must respond to work" do
    _(@worker).must_respond_to :work
  end
end

outputs a failure:

  1) Failure:
Worker#test_0001_must respond to work [bug11.rb:16]:
Expected #<Object:0x007f9e7184f0a0> (Object) to respond to #work.

Worker is a SimpleDelegate which in 1.9+ is a subclass of BasicObject. Expectations are put on Object (one level down) so the Worker (SimpleDelegate) hits method_missing and delegates down to the Object.new instance. That object doesn’t respond to work so the test fails.

You can bypass SimpleDelegate#method_missing by extending the worker with Minitest::Expectations. You can either do that in your setup at the instance level, like:

before do
  @worker = Worker.new(Object.new)
  @worker.extend Minitest::Expectations
end

or you can extend the Worker class (within the test file!), like:

class Worker
  include ::Minitest::Expectations
end

How to share code across test classes?

Use a module. That’s exactly what they’re for:

module UsefulStuff
  def useful_method
    # ...
  end
end

describe Blah do
  include UsefulStuff

  def test_whatever
    # useful_method available here
  end
end

Remember, describe simply creates test classes. It’s just ruby at the end of the day and all your normal Good Ruby Rules (tm) apply. If you want to extend your test using setup/teardown via a module, just make sure you ALWAYS call super. before/after automatically call super for you, so make sure you don’t do it twice.

How to run code before a group of tests?

Use a constant with begin…end like this:

describe Blah do
  SETUP = begin
     # ... this runs once when describe Blah starts
  end
  # ...
end

This can be useful for expensive initializations or sharing state. Remember, this is just ruby code, so you need to make sure this technique and sharing state doesn’t interfere with your tests.

Why am I seeing uninitialized constant MiniTest::Test (NameError)?

Are you running the test with Bundler (e.g. via bundle exec )? If so, in order to require minitest, you must first add the gem 'minitest' to your Gemfile and run bundle. Once it’s installed, you should be able to require minitest and run your tests.

Prominent Projects using Minitest:

  • arel

  • journey

  • mime-types

  • nokogiri

  • rails (active_support et al)

  • rake

  • rdoc

  • …and of course, everything from seattle.rb…

Developing Minitest:

Minitest requires Hoe.

Minitest’s own tests require UTF-8 external encoding.

This is a common problem in Windows, where the default external Encoding is often CP850, but can affect any platform. Minitest can run test suites using any Encoding, but to run Minitest’s own tests you must have a default external Encoding of UTF-8.

If your encoding is wrong, you’ll see errors like:

--- expected
+++ actual
@@ -1,2 +1,3 @@
 # encoding: UTF-8
 -"Expected /\\w+/ to not match \"blah blah blah\"."
 +"Expected /\\w+/ to not match # encoding: UTF-8
 +\"blah blah blah\"."

To check your current encoding, run:

ruby -e 'puts Encoding.default_external'

If your output is something other than UTF-8, you can set the RUBYOPTS env variable to a value of ‘-Eutf-8’. Something like:

RUBYOPT='-Eutf-8' ruby -e 'puts Encoding.default_external'

Check your OS/shell documentation for the precise syntax (the above will not work on a basic Windows CMD prompt, look for the SET command). Once you’ve got it successfully outputing UTF-8, use the same setting when running rake in Minitest.

Minitest’s own tests require GNU (or similar) diff.

This is also a problem primarily affecting Windows developers. PowerShell has a command called diff, but it is not suitable for use with Minitest.

If you see failures like either of these, you are probably missing diff tool:

  4) Failure:
TestMinitestUnitTestCase#test_assert_equal_different_long [D:/ruby/seattlerb/minitest/test/minitest/test_minitest_test.rb:936]:
Expected: "--- expected\n+++ actual\n@@ -1 +1 @@\n-\"hahahahahahahahahahahahahahahahahahahaha\"\n+\"blahblahblahblahblahblahblahblahblahblah\"\n"
  Actual: "Expected: \"hahahahahahahahahahahahahahahahahahahaha\"\n  Actual: \"blahblahblahblahblahblahblahblahblahblah\""

  5) Failure:
TestMinitestUnitTestCase#test_assert_equal_different_collection_hash_hex_invisible [D:/ruby/seattlerb/minitest/test/minitest/test_minitest_test.rb:845]:
Expected: "No visible difference in the Hash#inspect output.\nYou should look at the implementation of #== on Hash or its members.\n
{1=>#<Object:0xXXXXXX>}"
  Actual: "Expected: {1=>#<Object:0x00000003ba0470>}\n  Actual: {1=>#<Object:0x00000003ba0448>}"

If you use Cygwin or MSYS2 or similar there are packages that include a GNU diff for Windows. If you don’t, you can download GNU diffutils from gnuwin32.sourceforge.net/packages/diffutils.htm (make sure to add it to your PATH).

You can make sure it’s installed and path is configured properly with:

diff.exe -v

There are multiple lines of output, the first should be something like:

diff (GNU diffutils) 2.8.1

If you are using PowerShell make sure you run diff.exe, not just diff, which will invoke the PowerShell built in function.

Known Extensions:

capybara_minitest_spec

Bridge between Capybara RSpec matchers and Minitest::Spec expectations (e.g. page.must_have_content("Title")).

color_pound_spec_reporter

Test names print Ruby Object types in color with your Minitest Spec style tests.

minispec-metadata

Metadata for describe/it blocks & CLI tag filter. E.g. it "requires JS driver", js: true do & ruby test.rb --tag js runs tests tagged :js.

minispec-rails

Minimal support to use Spec style in Rails 5+.

mini-apivore

for swagger based automated API testing.

minitest-around

Around block for minitest. An alternative to setup/teardown dance.

minitest-assert_errors

Adds Minitest assertions to test for errors raised or not raised by Minitest itself.

minitest-autotest

autotest is a continuous testing facility meant to be used during development.

minitest-bacon

minitest-bacon extends minitest with bacon-like functionality.

minitest-bang

Adds support for RSpec-style let! to immediately invoke let statements before each test.

minitest-bisect

Helps you isolate and debug random test failures.

minitest-blink1_reporter

Display test results with a Blink1.

minitest-capistrano

Assertions and expectations for testing Capistrano recipes.

minitest-capybara

Capybara matchers support for minitest unit and spec.

minitest-cc

It provides minimal information about code coverage.

minitest-chef-handler

Run Minitest suites as Chef report handlers

minitest-ci

CI reporter plugin for Minitest.

minitest-context

Defines contexts for code reuse in Minitest specs that share common expectations.

minitest-debugger

Wraps assert so failed assertions drop into the ruby debugger.

minitest-display

Patches Minitest to allow for an easily configurable output.

minitest-documentation

Minimal documentation format inspired by rspec’s.

minitest-doc_reporter

Detailed output inspired by rspec’s documentation format.

minitest-emoji

Print out emoji for your test passes, fails, and skips.

minitest-english

Semantically symmetric aliases for assertions and expectations.

minitest-excludes

Clean API for excluding certain tests you don’t want to run under certain conditions.

minitest-fail-fast

Reimplements RSpec’s “fail fast” feature

minitest-filecontent

Support unit tests with expectation results in files. Differing results will be stored again in files.

minitest-filesystem

Adds assertion and expectation to help testing filesystem contents.

minitest-firemock

Makes your Minitest mocks more resilient.

minitest-focus

Focus on one test at a time.

minitest-gcstats

A minitest plugin that adds a report of the top tests by number of objects allocated.

minitest-global_expectations

Support minitest expectation methods for all objects

minitest-great_expectations

Generally useful additions to minitest’s assertions and expectations.

minitest-growl

Test notifier for minitest via growl.

minitest-happy

GLOBALLY ACTIVATE MINITEST PRIDE! RAWR!

minitest-have_tag

Adds Minitest assertions to test for the existence of HTML tags, including contents, within a provided string.

minitest-heat

Reporting that builds a heat map of failure locations

minitest-hooks

Around and before_all/after_all/around_all hooks

minitest-hyper

Pretty, single-page HTML reports for your Minitest runs

minitest-implicit-subject

Implicit declaration of the test subject.

minitest-instrument

Instrument ActiveSupport::Notifications when test method is executed.

minitest-instrument-db

Store information about speed of test execution provided by minitest-instrument in database.

minitest-junit

JUnit-style XML reporter for minitest.

minitest-keyword

Use Minitest assertions with keyword arguments.

minitest-libnotify

Test notifier for minitest via libnotify.

minitest-line

Run test at line number.

minitest-logger

Define assert_log and enable minitest to test log messages. Supports Logger and Log4r::Logger.

minitest-macruby

Provides extensions to minitest for macruby UI testing.

minitest-matchers

Adds support for RSpec-style matchers to minitest.

minitest-matchers_vaccine

Adds assertions that adhere to the matcher spec, but without any expectation infections.

minitest-metadata

Annotate tests with metadata (key-value).

minitest-mock_expectations

Provides method call assertions for minitest.

minitest-mongoid

Mongoid assertion matchers for Minitest.

minitest-must_not

Provides must_not as an alias for wont in Minitest.

minitest-optional_retry

Automatically retry failed test to help with flakiness.

minitest-osx

Reporter for the Mac OS X notification center.

minitest-parallel_fork

Fork-based parallelization

minitest-parallel-db

Run tests in parallel with a single database.

minitest-power_assert

PowerAssert for Minitest.

minitest-predicates

Adds support for .predicate? methods.

minitest-profile

List the 10 slowest tests in your suite.

minitest-rails

Minitest integration for Rails 3.x.

minitest-rails-capybara

Capybara integration for Minitest::Rails.

minitest-reporters

Create customizable Minitest output formats.

minitest-rg

Colored red/green output for Minitest.

minitest-rspec_mocks

Use RSpec Mocks with Minitest.

minitest-server

minitest-server provides a client/server setup with your minitest process, allowing your test run to send its results directly to a handler.

minitest-sequel

Minitest assertions to speed-up development and testing of Ruby Sequel database setups.

minitest-shared_description

Support for shared specs and shared spec subclasses

minitest-should_syntax

RSpec-style x.should == y assertions for Minitest.

minitest-shouldify

Adding all manner of shoulds to Minitest (bad idea)

minitest-snail

Print a list of tests that take too long

minitest-spec-context

Provides rspec-ish context method to Minitest::Spec.

minitest-spec-expect

Expect syntax for Minitest::Spec (e.g. expect(sequences).to_include :celery_man).

minitest-spec-magic

Minitest::Spec extensions for Rails and beyond.

minitest-spec-rails

Drop in Minitest::Spec superclass for ActiveSupport::TestCase.

minitest-sprint

Runs (Get it? It’s fast!) your tests and makes it easier to rerun individual failures.

minitest-stately

Find leaking state between tests

minitest-stub_any_instance

Stub any instance of a method on the given class for the duration of a block.

minitest-stub-const

Stub constants for the duration of a block.

minitest-tags

Add tags for minitest.

minitest-unordered

Adds a new assertion to minitest for checking the contents of a collection, ignoring element order.

minitest-vcr

Automatic cassette management with Minitest::Spec and VCR.

minitest_log

Adds structured logging, data explication, and verdicts.

minitest_owrapper

Get tests results as a TestResult object.

minitest_should

Shoulda style syntax for minitest test::unit.

minitest_tu_shim

Bridges between test/unit and minitest.

mongoid-minitest

Minitest matchers for Mongoid.

mutant-minitest

Minitest integration for mutant.

pry-rescue

A pry plugin w/ minitest support. See pry-rescue/minitest.rb.

rematch

Declutter your test files from large hardcoded data and update them automatically when your code changes.

rspec2minitest

Easily translate any RSpec matchers to Minitest assertions and expectations.

stubberry

Multiple stubbing ‘berries’, sweet and useful stub helpers and assertions. ( stub_must, assert_method_called, stubbing ORM objects by id )

Unknown Extensions:

Authors… Please send me a pull request with a description of your minitest extension.

  • assay-minitest

  • detroit-minitest

  • em-minitest-spec

  • flexmock-minitest

  • guard-minitest

  • guard-minitest-decisiv

  • minitest-activemodel

  • minitest-ar-assertions

  • minitest-capybara-unit

  • minitest-colorer

  • minitest-deluxe

  • minitest-extra-assertions

  • minitest-rails-shoulda

  • minitest-spec

  • minitest-spec-should

  • minitest-sugar

  • spork-minitest

Minitest related goods

REQUIREMENTS:

  • Ruby 2.3+. No magic is involved. I hope.

INSTALL:

sudo gem install minitest

On 1.9, you already have it. To get newer candy you can still install the gem, and then requiring “minitest/autorun” should automatically pull it in. If not, you’ll need to do it yourself:

gem "minitest"     # ensures you"re using the gem, and not the built-in MT
require "minitest/autorun"

# ... usual testing stuffs ...

DO NOTE: There is a serious problem with the way that ruby 1.9/2.0 packages their own gems. They install a gem specification file, but don’t install the gem contents in the gem path. This messes up Gem.find_files and many other things (gem which, gem contents, etc).

Just install minitest as a gem for real and you’ll be happier.

LICENSE:

(The MIT License)

Copyright © Ryan Davis, seattle.rb

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

minitest's People

Contributors

drbrain avatar zenspider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minitest's Issues

undefined method `dependency' for Hoe when (called from Arel's Rakefile)

Minitest commit 5427f8a seems to have introduced a call to a nonexistent 'dependency' method. This makes it impossible to run the Arel tests. I would submit a patch if I knew the right fix but I don't.

I tried this in ree and 1.9.2.

To reproduce:

  1. git clone https://github.com/rails/arel.git
  2. cd arel
  3. bundle
  4. rake --trace

RESULT:

rake/rdoctask is deprecated.  Use rdoc/task instead (in RDoc 2.4.2+)
rake aborted!
undefined method `dependency' for #<Hoe:0x10198cab8>
/Users/brian/.rvm/gems/ree-1.8.7-2011.03/gems/minitest-2.3.1/lib/hoe/minitest.rb:6:in `initialize_minitest'
<snip>
/Users/brian/Code/arel/Rakefile:10

#must_output not recognized in v2.7.0

INITIAL SETUP

  1. Mac OS X Lion v10.7.2
  2. RVM v1.9.0
  3. Ruby v1.9.2-p290 (default Ruby)
  4. Install minitest gem v2.7.0

REPRO STEPS

  1. Write test case as below.
  2. Save as 'test.rb'
  3. Execute test case: ruby test.rb

Test Case

require 'minitest/spec'
require 'minitest/autorun'

describe 'test' do
  it 'will respond to must_output' do
    proc { puts 'foo' }.must_output 'foo'
  end
end

EXPECTED

Test to pass.

ACTUAL

Test raises an error: NoMethodError: undefined method must_output' for #<Proc:[email protected]:6> test.rb:6:inblock (2 levels) in

'

MiniTest::Mock should use newer same-method expects over older ones

I don't know if this is bad form or something, but I'd like to be able to do something like the following:

require 'minitest/autorun'

class Foo
  def initialize(obj)
    @obj = obj
  end

  def bar?
    !!@obj.baz
  end
end

describe Foo do
  describe '#bar?' do
    it 'should return true and false correctly' do
      obj = MiniTest::Mock.new
      foo = Foo.new(obj)

      obj.expect :baz, nil
      foo.bar?.must_equal false

      obj.expect :baz, 1
      foo.bar?.must_equal true

      obj.verify
    end
  end
end

Allow #must_be and #wont_be to test truthiness / falsiness

I appreciate issue #31. Along those lines it would be nice to be able to test truthiness and falsiness without comparing a result to true or false.

Instead of this:

some_obj.truthy_method.must_equal true
some_obj.falsy_method.must_equal false

It would be nice to do this:

some_obj.truthy_method.must_be
some_obj.falsy_method.wont_be

I.e., use MiniTest::Spec to test Ruby's idiomatic Boolean logic where nil and false are falsy and everything else is truthy. I can already do this with MiniTest::Unit:

assert(some_obj.truthy_method)
refute(some_obj.falsy_method)

Note: at first I considered adding Object#truthy? and Object#falsy? methods and using must_be :truthy? etc. But I think the 0-arg must_be and wont_be methods are nicer in two ways: they don't add methods to Object and they are slightly more concise.

(And no, I didn't get this idea from RSpec. :-)

Filter backtrace not filtering out minitest

The current setting for MINI_DIR:

MINI_DIR = File.dirname(File.dirname(file))

Evaluates to like this for me:

./../../../.rvm/gems/ree-1.8.7-2011.03@mygemset/gems/minitest-2.6.0/lib

Where as, it's trying to filter out lines like this:

/Users/nathany/.rvm/gems/ree-1.8.7-2011.03@mygemset/gems/minitest-2.6.0/lib/minitest/unit.rb:179:in `assert'

So perhaps it should instead be defined as?

MINI_DIR = File.expand_path(File.dirname(File.dirname(file))) # :nodoc:

Minitest::filter_backtrace strips too much for tests run in ruby trunk

When running tests in Ruby Trunk I see an error like this:

Line 82 of test_pipeline.rb doesn't raise an exception, it calls into Net::HTTP where it raises an error somewhere inside the library.

  1) Error:
test_pipeline_retry(TestNetHttpPipeline):
Errno::EPIPE: Broken pipe
    /Users/drbrain/Work/svn/ruby/trunk/test/net/http/test_pipeline.rb:82:in `block in test_pipeline_retry'
    /Users/drbrain/Work/svn/ruby/trunk/test/net/http/utils.rb:11:in `start'
    /Users/drbrain/Work/svn/ruby/trunk/test/net/http/test_pipeline.rb:81:in `test_pipeline_retry'
    ./test/runner.rb:15:in `<main>'

The root of the problem is that MINI_DIR is the same path as the library files when running tests using make test in ruby trunk.

Editing Test::Unit#puke (which calls Minitest::filter_backtrace directly) to remove the filtering entirely gives this output:

  1) Error:
test_pipeline_retry(TestNetHttpPipeline):
Errno::EPIPE: Broken pipe
    /Users/drbrain/Work/svn/ruby/trunk/lib/net/protocol.rb:199:in `write'
    /Users/drbrain/Work/svn/ruby/trunk/lib/net/protocol.rb:199:in `write0'
    /Users/drbrain/Work/svn/ruby/trunk/lib/net/protocol.rb:173:in `block in write'
    /Users/drbrain/Work/svn/ruby/trunk/lib/net/protocol.rb:190:in `writing'
    /Users/drbrain/Work/svn/ruby/trunk/lib/net/protocol.rb:172:in `write'
    /Users/drbrain/Work/svn/ruby/trunk/lib/net/http.rb:2349:in `write_header'
    /Users/drbrain/Work/svn/ruby/trunk/lib/net/http.rb:2197:in `exec'
    /Users/drbrain/Work/svn/ruby/trunk/lib/net/http.rb:1646:in `pipeline_send'
    /Users/drbrain/Work/svn/ruby/trunk/lib/net/http.rb:1419:in `pipeline'
    /Users/drbrain/Work/svn/ruby/trunk/test/net/http/test_pipeline.rb:82:in `block in test_pipeline_retry'
    /Users/drbrain/Work/svn/ruby/trunk/lib/net/http.rb:825:in `start'
    /Users/drbrain/Work/svn/ruby/trunk/test/net/http/utils.rb:11:in `start'
    /Users/drbrain/Work/svn/ruby/trunk/test/net/http/test_pipeline.rb:81:in `test_pipeline_retry'
    /Users/drbrain/Work/svn/ruby/trunk/lib/minitest/unit.rb:949:in `run'
    /Users/drbrain/Work/svn/ruby/trunk/lib/test/unit/testcase.rb:17:in `run'
    /Users/drbrain/Work/svn/ruby/trunk/lib/minitest/unit.rb:787:in `block in _run_suite'
    /Users/drbrain/Work/svn/ruby/trunk/lib/minitest/unit.rb:780:in `map'
    /Users/drbrain/Work/svn/ruby/trunk/lib/minitest/unit.rb:780:in `_run_suite'
    /Users/drbrain/Work/svn/ruby/trunk/lib/test/unit.rb:565:in `block in _run_suites'
    /Users/drbrain/Work/svn/ruby/trunk/lib/test/unit.rb:563:in `each'
    /Users/drbrain/Work/svn/ruby/trunk/lib/test/unit.rb:563:in `_run_suites'
    /Users/drbrain/Work/svn/ruby/trunk/lib/minitest/unit.rb:746:in `_run_anything'
    /Users/drbrain/Work/svn/ruby/trunk/lib/minitest/unit.rb:909:in `run_tests'
    /Users/drbrain/Work/svn/ruby/trunk/lib/minitest/unit.rb:896:in `block in _run'
    /Users/drbrain/Work/svn/ruby/trunk/lib/minitest/unit.rb:895:in `each'
    /Users/drbrain/Work/svn/ruby/trunk/lib/minitest/unit.rb:895:in `_run'
    /Users/drbrain/Work/svn/ruby/trunk/lib/minitest/unit.rb:884:in `run'
    /Users/drbrain/Work/svn/ruby/trunk/lib/test/unit.rb:21:in `run'
    /Users/drbrain/Work/svn/ruby/trunk/lib/test/unit.rb:606:in `run'
    /Users/drbrain/Work/svn/ruby/trunk/lib/test/unit.rb:638:in `run'
    /Users/drbrain/Work/svn/ruby/trunk/lib/test/unit.rb:642:in `run'
    ./test/runner.rb:15:in `<main>'

must_be and wont_be with predicates not working

From lines 335-337 in lib/minitest/spec.rb, I understood that must_be (and wont_be) can call a method and test for truthiness. But if I write a test like

user.must_be :valid?

minitest throws an ArgumentError.

ArgumentError: wrong number of arguments (2 for 3)
    (eval):4:in `must_be'

These methods are calling assert_operator which indeed require 3 arguments and is not calling what I think should be assert_predicate.

Correct way to include in ruby 1.8/rails 3 project.

I was under the impression that I should be able to include the minitest gem in a ruby 1.8/rails 3 project, and have it fulfill the activesupport::testcase dependency on test/unit/testcase, but that doesn't appear to be happening. Is a particular load order required for this to work?

before not called ?

As a first attempt at using MiniTest with RoR I'm facing the following problem.

Enviromnet:

  • MiniTest gem version 2.6.1
  • RoR 3.1 project running on ruby 1.9.2p290.

The file test/unit/user_test.rb contains the following spec:

describe User do

  before do
    @greeting = "Hello, world"
  end

  describe "greeting" do
    it "should contain a greeting" do
      assert @greeting, "must not be nil"
    end
  end

end

The test fails (i.e. @Greeting is nil) and reports back also the following

block (2 levels) in <top (required)>

I run the whole thing using rake test:units.

Mock: expect method that raise an exception

I was trying to switch from Mocha to MiniTest Mock. But I haven't find a way to make a mock object to expect some method that raise an exception. For example, here is a simplified version of the test that I have.

bank = mock
bank.expects(:exchange_with).raises(Money::Bank::UnknownRate)
assert_equal "N/A", formatted_money(123.to_money(:usd), :aaa, bank)

formatted_money is returning a string with nice representation of money in the specified currency. But when the currency does not exist bank won't know how to convert the money and will raise an exception. In that case formatted_money should just return "N/A".

I have read the minitest/mock.rb and I don't have any ideas how to integrate this in a simple way, unfortunately :-(

Gem::Deprecate

Hi folks,

The release pushed yesterday (2.12.0) uses Gem::Deprecate which was moved under that name in RubyGems 1.8.11 (2011-10-03):
rubygems/rubygems@795290d

This breaks MiniTest on older versions of RubyGems (typically if installed from OS packages).

It's fine to require people to upgrade but just wondering if you want to keep it working on ancient versions?

Cheers,

Andrew.

How to get rid of warning

I have this warning coming up in some of my tests: "MiniTest::MINI_DIR was removed. Don't violate other's internals." Any hints on how to get rid of it?

`current': uninitialized class variable @@current_spec in MiniTest::Spec

Got a problem then I've tried to test that string contains a substring in the Sinatra app.

1.9.3: minitest/spec.rb:142: in current': uninitialized class variable @@current_spec in MiniTest::Spec (NameError) from (eval):6:inmust_include'...

Problem version (MiniTest::Spec):

require 'minitest/spec'
require 'rack/test'

include Rack::Test::Methods

describe "App" do
  describe "GET /" do
    get '/'
    last_response.body.must_include("substring")
  end
end

Working version (MiniTest::Unit):

require 'minitest/unit'
require 'rack/test'

include Rack::Test::Methods

class TestApp < MiniTest::Unit::TestCase
  def test_root_path
    get '/'
    assert last_response.body.include?("substring")
  end
end

I hope that anybody can help me. Thank you.

gem minitest + Test::Unit::TestCase: uninitialized constant MiniTest::MINI_DIR

Hi,
I found that this code:

require 'test_helper'

class PostTest < ActiveSupport::TestCase
  test "respond_to" do
    assert_respond_to 1, :to_s
  end
end

produces following exception:

test_respond_to(PostTest):
NameError: uninitialized constant MiniTest::MINI_DIR
    /Users/wojtek/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/test/unit/assertions.rb:253:in `assert_respond_to'

When I remove gem activiation for minitest, it works fine. Note I was using Rails here, but same thing happens when my test case subclasses Test::Unit::TestCase directly (ActiveSupport::TestCase does it).

find me!

find me using omnifocus-github

MiniTest::Spec stomping on the name?

ActionController::TestCase uses the name method in determine_default_controller_class.

When minitest_tu_shim subclasses TestCase < ::MiniTest::Unit::TestCase it works fine. Changing TestCase to subclass ::MiniTest::Spec results in name being nil when it reaches the determine_default_controller_class method in Rails. This is without changing my tests at all, they still inherit the usual way, not using the describe block.

The same issue is mentioned on MetaSkills.net, where it mentions the workaround of using tests in every controller. I thought it was worth raising the issue, just in case it is a bug.

My setup is: Ruby Enterprise 1.8.7, Rails 2.3.14, tried both the Minitest gem and master.

Spec output

What do you think to add a spec reporter like rspec?

minitest 2.10.0 fails tests with ruby 1.9

With ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux] I'm getting the following test failures:

  1) Failure:
test_run_error_teardown(TestMiniTestUnit) [/var/tmp/portage/dev-ruby/minitest-2.10.0/work/ruby19/minitest-2.10.0/test/test_minitest_unit.rb:249]:
--- expected
+++ actual
@@ -9,7 +9,7 @@
   1) Error:
 test_something(ATestCase):
 RuntimeError: unhandled exception
-    FILE:LINE:in `teardown'
+    /var/tmp/portage/dev-ruby/minitest-2.10.0/work/ruby19/minitest-2.10.FILE:LINE:in `teardown'

 1 tests, 1 assertions, 0 failures, 1 errors, 0 skips
 "


  2) Failure:
test_run_error(TestMiniTestUnit) [/var/tmp/portage/dev-ruby/minitest-2.10.0/work/ruby19/minitest-2.10.0/test/test_minitest_unit.rb:216]:
--- expected
+++ actual
@@ -9,7 +9,7 @@
   1) Error:
 test_error(ATestCase):
 RuntimeError: unhandled exception
-    FILE:LINE:in `test_error'
+    /var/tmp/portage/dev-ruby/minitest-2.10.0/work/ruby19/minitest-2.10.FILE:LINE:in `test_error'

 2 tests, 1 assertions, 0 failures, 1 errors, 0 skips
 "

MiniTest::Spec Expectations with Proc as receiver

When the receiver is a Proc for an expectation method an ArgumentError is raised since it will always have 1 less argument than it should.

For example:

p = Proc.new {}
p.must_be_instance_of Proc # ArgumentError: wrong number of arguments (1 for 2)
p.wont_be_nil # ArgumentError: wrong number of arguments (0 for 1)

# just for example purposes
p.must_be :==, p # ArgumentError: wrong number of arguments (2 for 3) 

(I'm working on some DSL-like code that accepts a Proc in various places and stores it latter use)

before doesn't get called

Hello folks,

my before calls are never executed. Maybe my spec_helper.rb is wrong:

ENV['RAILS_ENV'] = 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'minitest/autorun'

autoload :Fake, 'support/fake'

class MiniTest::Spec
  include ActiveSupport::Testing::SetupAndTeardown
  include Factory::Syntax::Methods

  alias :method_name :__name__ if defined? :__name__
end

Furthermore changing the before calls to setup methods works like expected, so I think this is a bug.

minitest-2.6.1 self test failure on hppa hpux-11.00, hpux-11.11, hpux-11.23 and hpux-11.31

...although the same test passes on ia64 hpux-11.23 and ia64 hpux-11.31.

I am using ruby-1.9.2 and I have already installed the gems: fattr-2.2.0, session-3.1.0, flexmock-0.9.0, rdoc-3.9.4 and rake-0.9.2.

Here's the test output:

/opt/TWWfsw/ruby19/bin/ruby -w -Ilib:bin:test:. -e 'require "rubygems"; require "minitest/autorun"; require "test/test_minitest_spec.rb"; require "test/test_minitest_unit.rb"; require "test/test_minitest_benchmark.rb"; require "test/test_minitest_mock.rb"' --                                                                                               
Run options: --seed 11055                                                                                             

# Running tests:                                                                                                      

................................................F.....................................................................
.........................................................................                                             

Finished tests in 1.103381s, 173.1043 tests/s, 452.2463 assertions/s.                                                 

  1) Failure:                                                                                                         
test_cls_bench_range(TestMiniTestBenchmark) [./test/test_minitest_benchmark.rb:29]:                                   
Expected: [1, 10, 100, 1000, 10000]                                                                                   
  Actual: [1, 10, 100, 1000]                                                                                          

191 tests, 499 assertions, 1 failures, 0 errors, 0 skips                                                              
rake aborted!                                                                                                         
Command failed with status (1): [/opt/TWWfsw/ruby19/bin/ruby -w -Ilib:bin:t...]                                       

Please ask if there's any additional information I can give to help you fix this.

MiniTest::Mock Example

Should the following mock example within the docs produce a single spec failure:

class MemeAsker
    def initialize(meme)
      @meme = meme
    end

    def ask(question)
      method = question.tr(" ","_") + "?"
      @meme.send(method)
    end
  end

  require 'minitest/autorun'

  describe MemeAsker do
    before do
      @meme = MiniTest::Mock.new
      @meme_asker = MemeAsker.new @meme
    end

    describe "#ask" do
      describe "when passed an unpunctuated question" do
        it "should invoke the appropriate predicate method on the meme" do
          @meme.expect :will_it_blend?, :return_value
          @meme_asker.ask "will it blend"
          @meme.verify
        end
      end
    end
  end

At this time, I'm seeing the following:


$ ruby meme_asker_spec.rb
Run options: --seed 60317

# Running tests:

E

Finished tests in 0.001315s, 760.4563 tests/s, 0.0000 assertions/s.

  1) Error:
test_0001_should_invoke_the_appropriate_predicate_method_on_the_meme(MemeAsker::#ask::when passed an unpunctuated question):
NoMethodError: unmocked method :send, expected one of [:will_it_blend?]
    meme_asker_spec.rb:8:in `ask'
    meme_asker_spec.rb:25:in `block (4 levels) in <main>'

1 tests, 0 assertions, 0 failures, 1 errors, 0 skips

MiniTest::Unit.after_tests is executed before tests under ruby 1.9.3.preview

# Uncomment to use v2.3.1 shipped as gem - the bug still occurs
# require 'rubygems'
# gem 'minitest'

require 'minitest/unit'
require 'minitest/autorun'

class MyTest < MiniTest::Unit::TestCase

  def test_vip
    assert true
  end

end

MiniTest::Unit.after_tests() { puts "after?" }

The output on ruby 1.9.2 when running the version from rubygems (because the version shipped with ruby does not have MiniTest::Unit.after_tests method implemented) is:

10:47 <ruby-1.9.2-p180> ~/develop/test/mini193  > ruby t_test.rb 
Run options: --seed 34973

# Running tests:

.

Finished tests in 0.000405s, 2468.2216 tests/s, 2468.2216 assertions/s.

1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
after?

The output form 1.9.3 (gem version or shipped with ruby - does not matter) is :

10:48 <ruby-1.9.3-preview1> ~/develop/test/mini193  > ruby t_test.rb 
after?
Run options: --seed 54324

# Running tests:

.

Finished tests in 0.000409s, 2446.2977 tests/s, 2446.2977 assertions/s.

1 tests, 1 assertions, 0 failures, 0 errors, 0 skips

My guess would be that something about at_exit behavior changed in 1.9.3 .

tags for releases in the repository?

Hi,

Currently, the repository does not show any tag corresponding to the different released versions of the project. Would it be possible to tag them (at least for the next releases), as it would ease the process of following evolution of the code.

Thanks!

Cédric

MiniTest::Expectations future and symmetry?

Hi, I noticed within the documentation that you're planning on removing the following:

#must_send

BTW, I just noticed the TODO comments within the documentation. Next, are you planning on adding the expectations: #must_be_silent, #wont_output, and #wont_raise to MiniTest? I'm wasn't sure if you were going for symmetry between
#must_* and #won't_*.

-Conrad

RSpec/Shoulda like matchers support

Hi, I'd like to know what you're thinking about possible matchers support in MiniTest::Spec.
You can see my take on it in with valid_attribute https://gist.github.com/1176601 and shoulda-matchers https://gist.github.com/1176619.

We could settle on an already used convention that a matcher must respond to description, matches?, does_not_match?, failure_message, negative_failure_message and possibly check this somehow.

As you can see minimal implementation is pretty straightforward and I wanted your opinion before actually integrating this into minitest or as a separate gem.

Allow regexp for assert_raises

I'd like an optional final regexp parameter to assert_raises so I can assert the message contents of the raised exception:

assert_raises ArgumentError, /Unsupported option/ do
  dc = Dalli::Client.new('localhost', :badopt => true)
end

Undef'ing methods breaks on Rubinius

The mocks that minitest defines, break Kernel#inspect on Rubinius. The problem is with the following lines:

https://github.com/seattlerb/minitest/blob/master/lib/minitest/mock.rb#L15-19

Here methods that Rubinius uses internally for inspecting objects are undefined, such as Object#tainted? to set the tainted status of the resulting inspect string. Other methods are for example Object#== that is used for inspecting Hash instances, which breaks when there are Mock objects stored in a Hash.

This issue results in backtraces such as the following:

NoMethodError: unmocked method :tainted?, expected one of [:rpush]
    kernel/common/kernel.rb:329:in `inspect'
    kernel/common/hash19.rb:510:in `inspect'
    kernel/common/hash19.rb:391:in `each_item'
    kernel/common/hash19.rb:507:in `inspect'
    kernel/common/thread.rb:52:in `detect_recursion'
    kernel/common/hash19.rb:506:in `inspect'
    kernel/common/hash19.rb:415:in `each_key'
    kernel/common/hash19.rb:391:in `each_item'
    kernel/common/hash19.rb:415:in `each_key'
    ../sidekiq/test/test_extensions.rb:41:in `TestExtensions'
    kernel/bootstrap/array19.rb:18:in `map'
    kernel/bootstrap/array19.rb:18:in `map'
    kernel/bootstrap/array.rb:68:in `each'
    kernel/loader.rb:712:in `run_at_exits'
    kernel/loader.rb:732:in `epilogue'
    kernel/loader.rb:863:in `main'

Adding more methods to the skip list seems like a bit of a brittle solution to me and having to prefix everything in Rubinius with __ also doesn't seem like a very viable solution, especially for cases like Object#==. I'm not really sure about what would be a proper way to fix this, but wanted to bring this issue to the attention.

assert_difference

Is there any reason why assert_difference isn't implemented in minitest?

Test/unit compatibility layer

Hi,
do you have any plans on implementing a compatibility layer for test/unit, as it is now bundled in Ruby 1.9.3? I think it would be more consistent - if you make some more significant changes, the bundled layer in Ruby 1.9.3 might get broken, but this way everything would be up-to-date in your gem (and also it would help older versions of Ruby use minitest as a faster substitute of test/unit).

Thanks,
Bohuslav.

Release tags?

Hello,

Will be great if the release tags can be pushed to Git/GitHub so things like diff compare can be performed between versions.

Thank you.

Allow #must_be And #wont_be to take one argument for query methods.

It might be kind of cool to do something like this.

@user.must_be :valid?

I know this would be equal to.

assert user.valid?

But it would be kind of nice to get the pretty output message given be supporting methods like #assert_operator. So I am suggesting that I could do a patch that would check the arity of the method and if only one is given and that method is a query method (ending in a "?") then it would do something like this.

assert o1.__send__(op), msg

Thoughts?

minitest failed with Ruby-1.9.2-p290 and Rails 3.1.3

when doing rails console, an error occurs:

/Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require': /Users/mac/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:673: class/module name must be CONSTANT (SyntaxError)
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `block in require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `block in load_dependency'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /Users/mac/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/test/unit/assertions.rb:1:in `<top (required)>'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `block in require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `block in load_dependency'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /Users/mac/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/test/unit/testcase.rb:1:in `<top (required)>'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `block in require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `block in load_dependency'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/test_case.rb:1:in `<top (required)>'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `block in require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `block in load_dependency'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/console/app.rb:2:in `<top (required)>'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `block in require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `block in load_dependency'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/application.rb:204:in `initialize_console'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/application.rb:114:in `load_console'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:27:in `start'
    from /Users/mac/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Impossible to mock #call

The implementation of pretty messages preempts Mock#call for its own purpose, thereby making it impossible to mock that method. Please just use another, non-conflicting name for the method.

Can you support equivalent of rspec before(:all)

That is a setup that runs once per TestCase. I've done some crazy things to work around this in test/unit over the years, and it's hard to believe that I've never seen it anywhere but rspec. If I have some time I might work on a patch, but I'm buried at the moment. Thoughts?

minitest project scaffolding?

Is there a way to generate the scaffolding for a Ruby project using mintiest after executing bundle gem project_name? For example,

MiniTest:

project_name
project_name/test
project_name/test/test_helper.rb
project_name/test/unit
project_name/test/functional
project_name/test/integration

MiniTestSpec:

project_name/spec
project_name/spec/spec_helper.rb
project_name/spec/unit
project_name/spec/functional
project_name/spec/integration

Also, some handy Rake tasks would be handy but I can grab those from the rspec project.

Unknown #io method in benchmark.rb:88

Is that method supposed to be defined by the runner ?

test_performance(TestAtomic):
NameError: undefined local variable or method `io' for #<TestAtomic:0x007ff3cc1aec40>
    /Users/zimbatm/.rvm/gems/ruby-1.9.2-p290/gems/minitest-2.4.0/lib/minitest/benchmark.rb:88:in `assert_performance'
    /Users/zimbatm/.rvm/gems/ruby-1.9.2-p290/gems/minitest-2.4.0/lib/minitest/benchmark.rb:176:in `assert_performance_linear'
    test/test_atomic.rb:67:in `test_performance'

3.0: Mock#expect too strict?

Somehow 3.0 sneaked into my project today, causing some of my tests to fail. I discovered it had to do with the new Mock#expect.

Here's an illustration of my use case:

require 'minitest/spec'
require 'minitest/mock'
require 'minitest/autorun'

describe 'Counter' do

  def mock_vending_machine(stuff={})
    mock = MiniTest::Mock.new
    mock.expect :vend, stuff
  end

  it "should count all candy" do
    machine = mock_vending_machine :gum => 2, :sour => 5
    total = 0
    total += machine.vend[:gum]
    total += machine.vend[:sour]
    total.must_equal 7
  end

end

The new 3.0 minitest gives me the error:

MockExpectationError: No more expects available for :vend: []

which, according to the changelog, is expected.

All I want to do, however, is mock a method call, regardless of how many times it's called. I can see the value of counting the number of calls in some cases, but a lot of times that makes the tests too brittle. Goes too far into implementation details, imo.

Anyways, is there a way to do a simple method stub in 3.0?

Alias 'describe' to 'context'.

I'd really like to have 'context' available as an alias to 'describe' in the tests I write using minitest/spec.
Below is a contrived example, but shows how I've used 'context' in the past:

describe MyCoolClass do
  context 'initialize' do
    before do
      @subject = MyCoolClass.new
    end

    it 'must create an instance of MyCoolClass' do
      @subject.must_be_instance_of(MyCoolClass) 
    end
  end
end

Any thoughts on an alias like this?
It's just DSL sugar but something I find useful when writing tests..

nested describes with different subjects

for me, it is not working:

Describe Class do
  subject { Class.new } 
  it { wont_be_nil }
 describe "field_X should have a default" do
   subject { Class.new.field_x }
   it { wont_be_nil } 
 end
end

gem: 2.11.4

MiniTest::Spec do not downcase

Would it be possible to not have the MiniTest::Spec#it method not downcase the desc argument?

Or, at the very least, provide some sort of option to prevent the downcase

refute_block method

Why is there no corresponding refute_block method for the assert_block method that MiniTest already supports?

The following implementation appears to work:

  def refute_block msg = nil
    msg = message(msg) { "Expected block to return false value" }
    refute yield, msg
  end

This just appears to be an oversight in providing assert/refute method pairs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.