'Use "vanilla" assert in Rspec?

How can someone use vanilla assert in Rspec?

require 'rspec'

describe MyTest do
  it 'tests that number 1 equals 1' do
    assert 1 == 1
  end
end

The error I get:

undefined method `assert' for
#<RSpec::ExampleGroups::Metadata::LoadFile:0x00000002b232a0>

Notice that I don't want to use assert_equal, eq, should, or other mumbo jumbo.



Solution 1:[1]

Configure RSpec to use MiniTest

RSpec.configure do |rspec|
  rspec.expect_with :stdlib
end

Then you can use all the asserts offered by MiniTest from the standard library.

...or Wrong

Alternatively, you can use Wrong if you like asserts with a block:

require 'wrong'

RSpec.configure do |rspec|
  rspec.expect_with Wrong
end
describe Set do
  specify "adding using the << operator" do
    set = Set.new
    set << 3 << 4
    assert { set.include?(3) }
  end

Inspired by this blog article on RSpec.info.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arnaud Meuret