Reputation: 27862
I have a test that looks like this:
class PageTest < ActiveSupport::TestCase
describe "test" do
test "should not save without attributes" do
page = Page.new
assert !page.save
end
end
end
When running the tests, I get 0 tests, 0 assertions
. If I remove the describe "test" do, I get the 1 test, 1 assertions
. So I have the feeling that the describe "..." do is actually making the test disappear.
What is going on here? What am I missing?
Upvotes: 2
Views: 136
Reputation: 12273
Looks like you're mixing up minitest specs
and ActiveSupport::TestCase
. If you check the rails guides on testing the test
method is explained but it's not used with describe
.
Rails adds a test method that takes a test name and a block. It generates a normal MiniTest::Unit test with method names prefixed with test_. So,
test "the truth" do
assert true
end
acts as if you had written
def test_the_truth
assert true
end
The describe
syntax is explained in the minitest docs under the spec
section and is used with it
(and not test
). Like so:
describe "when asked about cheeseburgers" do
it "must respond positively" do
@meme.i_can_has_cheezburger?.must_equal "OHAI!"
end
end
Upvotes: 1