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
26
votes
2 answers

How do I add gem 'minitest' to my test helper?

I am new to Ruby on Rails and testing. When I run rake test I get the following error: /Users/jarvis/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/rack-1.3.4/lib/rack/backports /uri/common_192.rb:53: warning: already initialized constant…
Nick Ruta
  • 450
  • 6
  • 14
25
votes
2 answers

What's the purpose of assigns method in Rails tests (MiniTest)?

Used in automatically generated tests: test "should create item" do login_user assert_difference('Item.count') do post :create, item: { creator: @item.creator, title: @item.title, user_id: @item.user_id, text: 'Hello, world!' } end …
Dan
  • 1,274
  • 2
  • 15
  • 32
25
votes
1 answer

Using Ruby and Minitest, how do I run the same testcase with different data, controlled only by a list

I have Ruby 2.0 code that operates on phone numbers, which I want to test using MiniTest. I have a function which takes a phone number arguments and tests it (including asserts). Each time I call that function, I want it to be a new test case. …
user2773661
  • 253
  • 3
  • 5
22
votes
1 answer

In Rails why is my mail body empty only in my test?

I have an actionmailer class and associated overhead, it works perfectly. In my unit test (rails default minitest) however, the email body is empty. Why is that? my mailer class: class TermsMailer < ApplicationMailer default from:…
Camden Narzt
  • 2,271
  • 1
  • 23
  • 42
21
votes
2 answers

Ruby: Mocking a class method with MiniTest?

I'm using MiniTest 2.12.1 (the latest version of the stock testing framework shipped with Ruby >= 1.9) and I can't figure out how to mock a class method with it, the same way it's possible with the likes of Mocha, for example: product =…
20
votes
5 answers

Using Minitest in Rails

Recently, I've read quite a few articles about Minitest. I really like the idea of a super lightweight test framework. I decided to replace rspec with it in a recent project and have had no luck getting it all to work. My problems are a) getting…
John Smith
  • 396
  • 1
  • 3
  • 10
20
votes
7 answers

How to fill_in datepicker using Capybara, Rails, MiniTest spec

I have a form_tag that generates the following HTML:
Marklar
  • 1,247
  • 4
  • 25
  • 48
19
votes
1 answer

Factory Girl pass parameter to trait

I've been banging my head over this. I want to be able to overwrite attributes on top of traits. I've been reading the documentation and some internet examples but I can't get it to work. This is sort of what I want to do: test "..." do #overwrite…
Gaston
  • 1,004
  • 1
  • 9
  • 23
18
votes
2 answers

Can minitest do something like "rspec --color --format doc"?

I want a pretty-printed summary of what tests are running, similar to rspec --color --format doc Can minitest do that?
Seamus Abshere
  • 8,326
  • 4
  • 44
  • 61
17
votes
2 answers

URI::InvalidURIError: bad URI(is not URI?) testing Rails controllers

I get URI::InvalidURIError testing Rails Home controller: require 'test_helper' class HomeControllerTest < ActionDispatch::IntegrationTest test "should get index" do get :index assert_response :success end end get the following…
Luca G. Soave
  • 12,271
  • 12
  • 58
  • 109
16
votes
1 answer

Getting Started with MiniTest and Rails

I want to switch an existing rails application from rspec to minitest starting with the models. Therefore I created a folder test. Inside there I created a file named minitest_helper.rb with the following content: require…
moonglum
  • 801
  • 5
  • 13
16
votes
1 answer

Rake doesn't know how to build tasks: default or minitest

I built a gem a while back and did not include any tests (shame on me). I've since attempted to redress this by including minitest, but I'm getting stuck right out of the gate with the following error: Don't know how to build task 'default' Here's…
michaelmichael
  • 13,755
  • 7
  • 54
  • 60
15
votes
2 answers

Ruby Minitest: Suite- or Class- level setup?

Using the built-in Ruby Minitest framework, is there a way to run some code once before the entire suite runs, or even once before an entire TestClass runs? I see in the answer to this question that Test::Unit::after_tests can be used to run code…
Dan Fuchs
  • 175
  • 1
  • 6
15
votes
7 answers

How to color unit tests with lib minitest or Test:Unit?

I would like to have unit tests output color in my dev environment. However, I can't make it work on Linux (Debian and Ubuntu). When I include the following libs: require 'minitest/autorun' require 'minitest/unit' require 'minitest/pride' I…
poseid
  • 6,986
  • 10
  • 48
  • 78
15
votes
4 answers

Testing a concern / module that uses ActiveRecord

SCENARIO I have extracted a concern called Taggable. It's a module that allows any model to support tagging. I have included this concern/module into models like User, Location, Places, Projects. I want to write tests for this module, but don't know…
alenm
  • 1,013
  • 3
  • 15
  • 34