Sha256: c510af4e487d9c76b0e2e9715d9f12ccf05d74fe61563c8f9b93c2a2e322aca5

Contents?: true

Size: 856 Bytes

Versions: 11

Compression:

Stored size: 856 Bytes

Contents

require 'test_helper'

class LocationMock < ServiceContract::Mock
  VALID_TYPES = %w(country state city county neighborhood postal_code)

  def self.type(version)
    SampleService.find(version).protocol("location").type("Location")
  end

  def self.customizations
    {
      "type" => -> { VALID_TYPES.sample }
    }
  end
end

class MockTest < Minitest::Test
  include ServiceContract::Assertions

  def test_mocking
    data = Array.new(2) { LocationMock.generate!(1) }

    service = SampleService.find(1)
    protocol = service.protocol("location")
    endpoint = protocol.endpoint("index")

    assert_endpoint_response(data, endpoint)

    # test customizations
    data.each do |datum|
      assert LocationMock::VALID_TYPES.include?(datum["type"]), "should be able to override a type generator with class level customizations"
    end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
service_contract-0.6.0 test/mock_test.rb
service_contract-0.5.1 test/mock_test.rb
service_contract-0.5.0 test/mock_test.rb
service_contract-0.4.1 test/mock_test.rb
service_contract-0.4.0 test/mock_test.rb
service_contract-0.3.0 test/mock_test.rb
service_contract-0.2.1 test/mock_test.rb
service_contract-0.2.0 test/mock_test.rb
service_contract-0.1.1 test/mock_test.rb
service_contract-0.1.0 test/mock_test.rb
service_contract-0.0.10 test/mock_test.rb