Sha256: 720f9507881124fcbfaa9d07889305bdc68407f68e252c5c1218da8e5b60dfd3

Contents?: true

Size: 772 Bytes

Versions: 6

Compression:

Stored size: 772 Bytes

Contents

require "test_helper"

class ActiveSupport::TestCase
  def self.test_data_mode(mode)
    case mode
    when :factory_bot
      require "factory_bot_rails"
      include FactoryBot::Syntax::Methods

      setup do
        TestData.uses_clean_slate
      end
    when :test_data
      setup do
        TestData.uses_test_data
      end
    end
  end
end

class SomeFactoryUsingTest < ActiveSupport::TestCase
  test_data_mode :factory_bot

  def test_boops
    create(:boop)

    assert_equal 1, Boop.count
  end
end

class SomeTestDataUsingTest < ActionDispatch::IntegrationTest
  test_data_mode :test_data

  def test_boops
    assert_equal 10, Boop.count
  end

  def test_factory_bot_method_is_not_on_this_class
    assert_raises(NameError) { method(:create) }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
test_data-0.3.2 example/test/integration/better_mode_switching_demo_test.rb
test_data-0.3.1 example/test/integration/better_mode_switching_demo_test.rb
test_data-0.3.0 example/test/integration/better_mode_switching_demo_test.rb
test_data-0.2.2 example/test/integration/better_mode_switching_demo_test.rb
test_data-0.2.1 example/test/integration/better_mode_switching_demo_test.rb
test_data-0.2.0 example/test/integration/better_mode_switching_demo_test.rb