NoMethodError <device name> in Rails and minitest / spec

Without minitest / spec, the test looks like this and the scales my_engine_customersload (all is well):

my_engine/test/models/my_engine/customer_test.rb is an

require 'test_helper'

module MyEngine
  class CustomerTest < ActiveSupport::TestCase

    test "alex is id 5" do
      assert my_engine_customers(:alex).id, 5
    end

  end
end

After adding require 'minitest/autorun'in test/test_helper.rband then converting the above test:

require 'test_helper'

describe MyEngine::Customer do

  let(:alex) { my_engine_customers(:alex) } # error here (error shown below)

  it "alex is id 5" do
    assert alex.id, 5
  end

end

I get this error:

NoMethodError: undefined method `my_engine_customers' for
#<#<Class:0x007fb63e8f09e8>:0x007fb63e81b068>

How do I access devices while using minitest / spec?

+4
source share
1 answer

spec DSL, Minitest::Spec . Rails ActiveSupport::TestCase , , ActionController::TestCase. - DSL ActionSupport::TestCase .

, ActiveSupport::TestCase DSL. , test_helper.rb:

class ActiveSupport::TestCase
  # Add spec DSL
  extend Minitest::Spec::DSL
end

( , ActiveSupport::TestCase.describe ? , , DSL, .)

-, spec DSL ActiveSupport::TestCase. DSL register_spec_type . test_helper.rb:

class ActiveSupport::TestCase
  # Use AS::TestCase for the base class when describing a model
  register_spec_type(self) do |desc|
    desc < ActiveRecord::Base if desc.is_a?(Class)
  end
end

, ActiveRecord, ActiveSupport::TestCase Minitest::Spec .

, DSL . - minitest-rails, require "minitest/rails" test_helper.rb. minitest-rails . ( .)

. blaurgh Minitest Spec Rails 4. </- >

+7

Source: https://habr.com/ru/post/1570741/


All Articles