2014-05-15 38 views
2

我在minitest中使用describe語法時遇到問題。當我運行時:ruby -Itest test/elasticsearch/es_record_test.rbminitest not pick up describe blocks

它只接受1測試,並沒有拿起描述塊中的一個。

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

下面是我當前的代碼:

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 

我test_helper.rb中是:

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 

我的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 

回答

0

兩個RSpec的和MINITEST定義describe方法。由於您在Gemfile中添加了rspec-rails,因此它使用RSpec。我不知道如何同時激活RSpec和Minitest的Spec DSL。

+0

你能想出如何讓這些工作在一起嗎?我現在正在處理這個問題。 – tibbon