Pithikos Pithikos - 1 year ago 103
Ruby Question

Use "vanilla" assert in Rspec?

How can someone use vanilla

in Rspec?

require 'rspec'

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

The error I get:

undefined method `assert' for

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

Answer Source

You can do this pretty easily:

require 'rspec/core'
require 'test/unit'

describe 'MyTest' do
  include Test::Unit::Assertions
  it 'tests that number 1 equals 1' do
    assert 1 == 2

(if you want to be able to run the tests by doing ruby foo.rb then you'll need to require rspec/autorun too). This pulls in all of those assertions. If you really don't want any extra assertions, just define your own assert method that raises an exception when the test should fail.

Conversely you can easily use respects expectation syntax outside of rspec by requiring rspec/expectations - rspec3 is designed to be modular.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download