Sha256: 8323d8e3ac1e36c871f4d19b9452545cc1b9f35f41fe0d5252dc6a4b04e3b76c

Contents?: true

Size: 1.37 KB

Versions: 30

Compression:

Stored size: 1.37 KB

Contents

module FixtureHelpers
  module InstanceMethods

    def stub_api_request(endpoint, options={})
      options = {
        :method => :get,
        :status => 200,
        :api_version => Restforce.configuration.api_version
      }.merge(options)

      stub = stub_request(options[:method], %r{/services/data/v#{options[:api_version]}/#{endpoint}})
      stub = stub.with(:body => options[:with_body]) if options[:with_body] && !RUBY_VERSION.match(/^1.8/)
      stub = stub.to_return(:status => options[:status], :body => fixture(options[:fixture]), :headers => { 'Content-Type' => 'application/json'}) if options[:fixture]
      stub
    end

    def stub_login_request(options={})
      stub = stub_request(:post, "https://login.salesforce.com/services/oauth2/token")
      stub = stub.with(:body => options[:with_body]) if options[:with_body] && !RUBY_VERSION.match(/^1.8/)
      stub
    end

    def fixture(f)
      File.read(File.expand_path("../../fixtures/#{f}.yml", __FILE__))
    end

  end

  module ClassMethods
    def requests(endpoint, options={})
      before do
        (@requests ||= []) << stub_api_request(endpoint, options)
      end

      after do
        @requests.each { |request| expect(request).to have_been_requested }
      end
    end
  end
end

RSpec.configure do |config|
  config.include FixtureHelpers::InstanceMethods
  config.extend FixtureHelpers::ClassMethods
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
openstax_active_force-1.1.1 spec/support/fixture_helpers.rb
active_force-0.24.0 spec/support/fixture_helpers.rb
active_force-0.23.0 spec/support/fixture_helpers.rb
active_force-0.22.1 spec/support/fixture_helpers.rb
active_force-0.22.0 spec/support/fixture_helpers.rb
active_force-0.21.0 spec/support/fixture_helpers.rb
active_force-0.20.1 spec/support/fixture_helpers.rb
active_force-0.20.0 spec/support/fixture_helpers.rb
active_force-0.19.0 spec/support/fixture_helpers.rb
active_force-0.18.0 spec/support/fixture_helpers.rb
active_force-0.17.0 spec/support/fixture_helpers.rb
active_force-0.16.0 spec/support/fixture_helpers.rb
active_force-0.15.1 spec/support/fixture_helpers.rb
active_force-0.15.0 spec/support/fixture_helpers.rb
openstax_active_force-1.1.0 spec/support/fixture_helpers.rb
openstax_active_force-1.0.0 spec/support/fixture_helpers.rb
active_force-0.7.1 spec/support/fixture_helpers.rb
active_force-0.7.0 spec/support/fixture_helpers.rb
active_force-0.6.1 spec/support/fixture_helpers.rb
active_force-0.6.0 spec/support/fixture_helpers.rb