Questions tagged [minitest]

a testing framework that comes in the standard library of Ruby 1.9.

Minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking. When making assertions in Cucumber step definitions, there are a few different libraries you could choose. MiniTest is one of the candidates.

MiniTest’s assertions are built into Ruby, which makes them a handy tool to reach for. They use a style of assertion that you’ll be familiar with if you’re used to making assertions in any xUnit testing framework.


Resources

1539 questions
14
votes
2 answers

Difference between "def setup" and "setup do" in Minitest?

Are there any differences at all between calling def setup and setup do in Rails Minitests? I had been using def setup this whole time, but I suddenly found that my setup for a particular test file was not being called. When I changed it to setup…
reesaspieces
  • 1,600
  • 4
  • 18
  • 47
14
votes
2 answers

Verify method never called or only once called using Minitest::Mock

Is there any way to verify a method never called or only a number of times called using Minitest::Mock Thanks in advance
Rnk Jangir
  • 711
  • 6
  • 23
14
votes
1 answer

Testing controllers with Minitest

I'm trying to find examples of testing controllers with Minitest, but I've only found a couple and the just verify what template is rendered and that 'success' is returned. That doesn't seem very helpful to me. Is Minitest used to test…
99miles
  • 10,942
  • 18
  • 78
  • 123
13
votes
5 answers

How to make minitest stop execution on failure?

I am using Minitest as the runner for my functional tests, using Selenium as the driver to run the browser. Each test is modeled as MiniTest::Unit::TestCase. Minitest reports summary of execution when it completes executing all tests. The Exceptions…
wanderer
  • 131
  • 1
  • 4
13
votes
4 answers

Minitest assertion failing on inspect

Whenever I try to assert_equal two objects, I always get errors like this: No visible difference in the User#inspect output. You should look at the implementation of #== on User or its members. It's happened with Time and Array as…
Fabian Silva
  • 705
  • 1
  • 7
  • 14
13
votes
2 answers

Minitest Issues Ruby on Rails

I'm reading the Ruby on Rails Tutorial by Michael Hartl and following along. I'm having problems however right when trying to do some testing. [fran@fran-desktop twitter-clone]$ bundle exec rake test /media/Data.II/Dropbox/Web…
FranGoitia
  • 1,965
  • 3
  • 30
  • 49
13
votes
4 answers

How to test Pundit policies with Minitest?

Gemfile gem 'pundit', '~> 0.2.1' app/controllers/application_controller.rb class ApplicationController < ActionController::Base include Pundit ... app/policies/application_policy.rb class ApplicationPolicy < Struct.new(:user, :record) def…
user664833
  • 18,397
  • 19
  • 91
  • 140
13
votes
1 answer

How to use Ruby MiniTest::Spec with Rails for API integration tests?

I'm building an app including a Rails API and want to use Ruby MiniTest::Spec to test. What's a good way to set it up? For example, good directory organization, good way to include files, etc.? I'm using the guidelines in the book Rails 3 In Action…
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
12
votes
2 answers

Multiple invocations of same method on a mock with minitest

I am using the version of minitest with Ruby 1.9.3 How do I test for multiple invocations of a mock with it? I need something like mockObject.expect.times(2) :method, [return_1 first time, return_2 second time] mockObject.verify Is there a way to…
user949110
  • 543
  • 7
  • 20
12
votes
1 answer

Rails and MiniTest: add additional folder

I use Ruby 2 and Rails 4. I have a folder test/lib, where a few tests are located. But running rake test does not use them. Only the other tests (models, controllers, ...) are running. Where do I have to add the lib folder? I already tried…
Bjoernsen
  • 2,016
  • 1
  • 33
  • 41
12
votes
3 answers

What does this MiniTest::Unit::TestCase warning mean?

My tests were running without problems, when suddenly the following warning appeared: MiniTest::Unit::TestCase is now Minitest::Test This was reported in the following libs: ruby-1.9.3-p392/lib/ruby/1.9.1/test/unit/testcase.rb:8:in…
Dave Isaacs
  • 4,499
  • 6
  • 31
  • 44
11
votes
2 answers

How do I mock and verify an ActionCable transmission in minitest?

I'm using Ruby on Rails 5.1 with ActionCable. I would like to use minitest to test a particular method, and mock the "ActionCable.server.broadcast" call to verify I'm sending out the right data I have module MyModule class Scanner def…
Dave
  • 15,639
  • 133
  • 442
  • 830
11
votes
6 answers

cannot load such file -- test_helper if test case run using 'ruby' instead of 'rake test'

If I run test case: ruby test/models/chat_bot/option_test.rb I get error: /home/anuja/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- test_helper (LoadError) and it works if I run…
Anuja
  • 646
  • 4
  • 14
11
votes
1 answer

Test helper method with Minitest

I would like to test a helper method using Minitest (minitest-rails) - but the helper method depends on current_user, a Devise helper method available to controllers and view. app/helpers/application_helper.rb def user_is_admin? …
user664833
  • 18,397
  • 19
  • 91
  • 140
11
votes
5 answers

Is there a consensus about test frameworks for Ruby 1.9.x?

A two-parter with a quick intro. Intro: I'm coming to Ruby from Perl, and I'm a bit lost among the test framework choices. I understand that there is probably no single, all-around best choice, but I can't even get a clear picture of the playing…
Telemachus
  • 19,459
  • 7
  • 57
  • 79