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
207
votes
16 answers

Is it possible to run a single test in MiniTest?

I can run all tests in a single file with: rake test TEST=path/to/test_file.rb However, if I want to run just one test in that file, how would I do it? I'm looking for similar functionality to: rspec path/to/test_file.rb -l 25
Josiah Kiehl
  • 3,593
  • 3
  • 26
  • 28
104
votes
4 answers

What is the expected syntax for checking exception messages in MiniTest's assert_raises/must_raise?

What is the expected syntax for checking exception messages in MiniTest's assert_raises/must_raise? I'm trying to make an assertion something like the following, where "Foo" is the expected error message: proc { bar.do_it }.must_raise…
kfitzpatrick
  • 2,425
  • 4
  • 19
  • 11
93
votes
3 answers

Is it possible to mark a test as pending in MiniTest?

And if this is possible, what is the syntax for this?
Lee McAlilly
  • 9,084
  • 12
  • 60
  • 94
76
votes
10 answers

How to run all tests with minitest?

I downloaded source code for a project, found a bug, and fixed it. Now I want to run tests to find out if I have broken anything. The Tests are in minitest DSL. How do I run them all at once? I searched for applicable rake tasks etc, but I didn't…
guai
  • 780
  • 1
  • 12
  • 29
71
votes
8 answers

How do I stub things in MiniTest?

Within my test I want to stub a canned response for any instance of a class. It might look like something like: Book.stubs(:title).any_instance().returns("War and Peace") Then whenever I call @book.title it returns "War and Peace". Is there a way…
Nick
  • 711
  • 1
  • 5
  • 3
68
votes
3 answers

How to organize minitest/unit tests?

After using RSpec for several projects, I'm giving minitest/unit a go. I'm liking it so far, but I miss using describe/context blocks to group my tests/specs in a logical way. I know minitest/spec provides this functionality, but I like that…
Doug Johnston
  • 855
  • 1
  • 7
  • 13
50
votes
2 answers

Minitest and Rspec

I have just watched a Railscast for Minitest. What are the pros and cons for using RSpec vs Minitest for testing a rails app? Which features will I lose converting from RSpec to Minitest?
GTDev
  • 5,488
  • 9
  • 49
  • 84
48
votes
7 answers

How to set up MiniTest?

I'm a fairly novice tester, but have been trying to get better at TDD in Rails. RSpec works great, but my tests are pretty slow. I've heard that MiniTest is a lot faster, and the MiniTest/Spec DSL looks pretty similar to how I'm used to working with…
Andrew
  • 42,517
  • 51
  • 181
  • 281
47
votes
8 answers

Before/After Suite when using Ruby MiniTest

Is there an alternative to RSpec's before(:suite) and after(:suite) in MiniTest? I suspect that a custom test runner is in order, however I cannot imagine it is not a common requirement, so somebody has probably implemented in. :-)
Nickolay Kolev
  • 1,179
  • 2
  • 9
  • 14
38
votes
5 answers

How to assert certain method is called with Ruby minitest framework?

I want to test whether a function invokes other functions properly with minitest Ruby, but I cannot find a proper assert to test from the doc. The source code class SomeClass def invoke_function(name) name == "right" ? right () : wrong () …
steveyang
  • 9,178
  • 8
  • 54
  • 80
34
votes
6 answers

How to use assert_select to test for presence of a given link?

My page should contain a link that looks like Click to go. How would you test for that using assert_select? I want to check for the presence of an a tag with href="/desired_path/1". How do you test the attributes of a…
B Seven
  • 44,484
  • 66
  • 240
  • 385
34
votes
3 answers

Why doesn't MiniTest::Spec have a wont_raise assertion?

Ruby's Test::Unit has assert_nothing_raised. Test::Unit has been replaced by MiniTest. Why don't MiniTest's assertions / expectations have anything parallel to this? For example you can expect must_raise but not wont_raise.
matt
  • 515,959
  • 87
  • 875
  • 1,141
31
votes
2 answers

minitest, test::unit, and rails

I read somewhere that 'minitest' is the "new test::unit for ruby 1.9.2+". But ruby 1.9.3 seems to include both test::unit and minitest, is that true? In the default rails testing, as outlined in the Rails testing guide.... things like…
jrochkind
  • 22,799
  • 12
  • 59
  • 74
29
votes
6 answers

How to assert the contents of an array, indifferent of the ordering

I have a minitest spec: it "fetches a list of all databases" do get "/v1/databases" json = JSON.parse(response.body) json.length.must_equal Database.count json.map{|d| d["id"]}.must_equal Database.all.pluck(:id) end This, however,…
berkes
  • 26,996
  • 27
  • 115
  • 206
29
votes
2 answers

How do I stub a method to raise an error using Ruby MiniTest?

I'm trying to test a Rails controller branch that is triggered when the model method raises an error. def my_controller_method @my_object = MyObject.find(params[:id]) begin result = @my_object.my_model_method(params) rescue…
s01ipsist
  • 3,022
  • 2
  • 32
  • 36
1
2 3
99 100