Sha256: da5fe85cfeebf73180a89cb5d6d36d0ddaab70c9afe650fbfdd0015fc1a74cb4

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module EacRailsGemSupport
  module Rspec
    module MinitestSupport
      def assert_difference(code, message = nil, compare_method = :not_to, &block)
        before_value = assert_difference_call(code)
        block.call
        after_value = assert_difference_call(code)
        expect(after_value).send(compare_method, eq(before_value), message)
      end

      def assert_no_difference(code, message = nil, &block)
        assert_difference(code, message, :to, &block)
      end

      def assert_equal(expected_value, actual_value, message = nil)
        expect(actual_value).to eq(expected_value), message
      end

      def assert_not(expected_value, message = nil)
        expect(expected_value).to be_falsy, message
      end

      def assert_not_equal(expected_value, actual_value, message = nil)
        expect(actual_value).not_to eq(expected_value), message
      end

      def assert_raise(*expected_types)
        expect { yield }.to raise_error(*expected_types)
      end

      private

      def assert_difference_call(code)
        if code.is_a?(::Proc)
          code.call
        elsif code.is_a?(::String)
          eval(code) # rubocop:disable Security/Eval
        else
          raise "Unmapped type for \"#{code}\""
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eac_rails_gem_support-0.7.2 lib/eac_rails_gem_support/rspec/minitest_support.rb
eac_rails_gem_support-0.7.1 lib/eac_rails_gem_support/rspec/minitest_support.rb
eac_rails_gem_support-0.7.0 lib/eac_rails_gem_support/rspec/minitest_support.rb