BC00
BC00

Reputation: 1639

minitest not picking up describe blocks

I am having an issue using the describe syntax in minitest. When I run: ruby -Itest test/elasticsearch/es_record_test.rb

Its only picking up 1 test, and not picking up the one in the describe block.

  pass: 1,  fail: 0,  error: 0, skip: 0
  total: 1 tests with 1 assertions in 0.075147 seconds

Below is my current code:

require "test_helper"

class EsRecordTest < Minitest::Spec
  let(:id) { '123' }
  let(:invalid_id) { '456' }
  let(:index_name) { 'es' }
  let(:index_type) { 'test' }
  let(:body) {{ :body => 'data' }}

  before do
    Elasticsearch::EsRecord.stub(:index_name, index_name) do
      Elasticsearch::EsRecord.stub(:index_type, index_type) do
        Elasticsearch::EsRecord.index(id, body)
      end
    end
  end

  it "should raise an error for unimplemented methods" do
    assert_raises NotImplementedError do
      Elasticsearch::EsRecord.index_name
      Elasticsearch::EsRecord.index_type
    end
  end

  describe "::delete_index_type" do 
    it 'should be able to delete an index type if the type exists' do
      assert Elasticsearch::EsRecord.delete_index_type(index_name, index_type)
    end
  end

My test_helper.rb is:

ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/rails"
require 'webmock/minitest'
require 'sidekiq/testing'
require 'typhoeus/adapters/faraday'

WebMock.disable_net_connect!(:allow_localhost => true)

Turn.config.format = :outline

class ActiveSupport::TestCase
  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
  fixtures :all

  # Add more helper methods to be used by all tests here...
  extend MiniTest::Spec::DSL

  register_spec_type self do |desc|
    desc < ActiveRecord::Base if desc.is_a? Class
  end
end

My gemfile:

gem "byebug", group: [:development, :test]
gem 'http_logger', require: true, group: [:development]
gem "minitest-rails", '~> 0.9', group: [:development, :test]


group :test do
  gem 'cucumber-rails', :require => false, group: [:test]
  gem 'selenium-webdriver', "~> 2.40.0"
  gem 'vcr'
  gem 'database_cleaner'
  gem 'webmock'
  gem 'elasticsearch-extensions'
  gem 'rspec-rails'
  gem 'turn'
  gem 'pickle', :git => "https://github.com/zgchurch/pickle.git"
end

Upvotes: 3

Views: 1230

Answers (1)

blowmage
blowmage

Reputation: 8984

Both RSpec and Minitest define the describe method. Since you have rspec-rails added in your Gemfile it is using RSpec. I don't know of a way to have both RSpec and Minitest's Spec DSL activated at the same time.

Upvotes: 1

Related Questions