我在使用minitest中的describe语法时遇到了问题。当我跑:ruby -Itest test/elasticsearch/es_record_test.rb
它只接受了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
我的宝石文件:
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 :(得分:0)
RSpec和Minitest都定义了describe
方法。由于您在rspec-rails
中添加了Gemfile
,因此正在使用RSpec。我不知道如何同时激活RSpec和Minitest的Spec DSL。