Problems running only one unit test on rails 4

4

When I run all tests or just tests of a file it is working normally, but when I try to run only a single test, it just does not spin.

I have this test

require 'test_helper'

class UserTest < ActiveSupport::TestCase

  test "is ban" do
    user = build(:user, role: :ban)
    assert user.banned?
  end

end

However, when I run this file, I have the expected response in the test

  

rake test test / models / user_test.rb

     

Run options: --seed 34310

     

Running tests:

     

.

     

Finished tests in 0.041871s, 23.8831 tests / s, 23.8831 assertions / s.

     

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

But when I want to run only a single function in the same way the rails documentation explains. ( link )

  

rake test test / models / user_test.rb is_ban

     

Run options: -n is_ban --seed 27215

     

Running tests:

     

Finished tests in 0.007734s, 0.0000 tests / s, 0.0000 assertions / s.

     

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

I do not have the is_ban test run, could anyone explain to me how I can only run a specific test? I've tried to do it in several ways and I was not successful.

I'm using Rails 4.0.2, Ruby 2.0 and I have some test gems installed like factory_girl, mocha and shoulda.

    
asked by anonymous 11.06.2014 / 04:06

1 answer

1

Quoting documentation , in free translation:

  

Rails adds a test method that receives a test name and a block. It generates a normal test of MiniTest::Unit , with the method name prefixed by test_ . So,

test "the truth" do
  assert true
end
     

is the same as writing

def test_the_truth
  assert true
end
     

The test macro only allows for a more readable name for the test. Anyway you can still use normal method definitions.

  

Running the tests is as simple as invoking the file containing the test cases using the% rake command.

$ rake test test/models/post_test.rb
.

Finished tests in 0.009262s, 107.9680 tests/s, 107.9680 assertions/s.

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

You can also run a particular test by running test and passing the method name.

$ rake test test/models/post_test.rb test_the_truth
.

Finished tests in 0.009064s, 110.3266 tests/s, 110.3266 assertions/s.

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

In short, use test instead of test_is_ban on the command line.

rake test test/models/user_test.rb test_is_ban
    
11.06.2014 / 13:29