Shoulda-matchers: Dependence issue with shoulda-matchers 3 and should 3.5

Created on 29 Oct 2015  路  12Comments  路  Source: thoughtbot/shoulda-matchers

Following installation instructions and since I'm using Minitest I've added both shoulda and shoulda-matchers to Gemfile.

Bundler could not find compatible versions for gem "shoulda-matchers":
  In snapshot (Gemfile.lock):
    shoulda-matchers (3.0.1)

  In Gemfile:
    shoulda (~> 3.5) ruby depends on
      shoulda-matchers (< 3.0, >= 1.4.1) ruby

Most helpful comment

@gamov @olimart @samuelpismel
I'm successfully using shoulda-matchers with standard MiniTest tests thanks to the minitest-matchers_vaccine gem:

_Gemfile_:

group :test do
  gem 'shoulda-matchers'
  gem 'minitest-matchers_vaccine'
end

_test_helper.rb_:

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :minitest
    with.library :rails
  end
end

_user_test.rb_:

class UserTest <  Minitest::Test
  def test_validation
    user = User.new
    assert_must validate_presence_of(:email), user
  end
end

or using @subject and must:

class UserTest < Minitest::Test
  def setup
    @subject = User.new
  end

  def test_validation
    must validate_presence_of :email
  end
end

All 12 comments

Yes, shoulda needs to be updated to support shoulda-matchers 3.x. I'll submit a PR over there. Thanks for reminding.

I'm delaying this until we get all of the 3.0.0 regressions under control.

In the meantime, I've updated the README to suggest that shoulda users use shoulda-matchers 2.8.0.

Is it possible, in the meantime, to use shoulda-matchers and minitest without shoulda-context (which provides the 'should' keyword?)? For example, calling them in some fashion in a regular test?

@gamov I've tried a bunch of things but all failed so I gave up and now waiting for the release (not sure what's holding on though).

Sorry to keep you waiting. I've created https://github.com/thoughtbot/shoulda/pull/261 to address this.

Any news on this? It would be nice to use pure minitest with shoulda matchers.

@gamov @olimart @samuelpismel
I'm successfully using shoulda-matchers with standard MiniTest tests thanks to the minitest-matchers_vaccine gem:

_Gemfile_:

group :test do
  gem 'shoulda-matchers'
  gem 'minitest-matchers_vaccine'
end

_test_helper.rb_:

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :minitest
    with.library :rails
  end
end

_user_test.rb_:

class UserTest <  Minitest::Test
  def test_validation
    user = User.new
    assert_must validate_presence_of(:email), user
  end
end

or using @subject and must:

class UserTest < Minitest::Test
  def setup
    @subject = User.new
  end

  def test_validation
    must validate_presence_of :email
  end
end

I have created a wiki page to help others with this problem: https://github.com/thoughtbot/shoulda-matchers/wiki/Usage-with-standard-MiniTest-tests

Thanks @zavan

That is really great! I'm guessing that you can use this gem alongside shoulda-context if you like? Has anyone tried this?

@mcmire I haven't tried it, but I think so. The gem is super simple:
https://github.com/rmm5t/minitest-matchers_vaccine/blob/master/lib/minitest/matchers_vaccine.rb

Was this page helpful?
0 / 5 - 0 ratings