Sha256: 181ab6b5f3e0b0fc55c6099fc205aa8c115a9ebad342b3ca6519f424730ba240

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

SPEC_ROOT = File.expand_path(File.dirname(__FILE__)) unless defined? SPEC_ROOT
$: << SPEC_ROOT
$: << File.join(File.dirname(__FILE__), '..', 'lib')
require 'rubygems'
require 'spec'
require 'yaml'
require 'webmock'
include WebMock::API

require 'rturk'
# RTurk.log.level = Logger::DEBUG

@aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
RTurk.setup(@aws['AWSAccessKeyId'], @aws['AWSAccessKey'], :sandbox => true)

def faker(response_name, opts = {})
  response = File.read(File.join(SPEC_ROOT, 'fake_responses', "#{response_name.to_s}.xml"))
  if opts[:operation]
    stub_request(:post, /amazonaws.com/).with(:body => /Operation=#{opts[:operation]}/).to_return(:body => response)
  elsif opts[:params]
    stub_request(:post, /amazonaws.com/).with do |request|
      opts[:params].reject do |key, value|
        !(request.body =~ /#{key}=#{value}/)
      end.length == opts[:params].length
    end.to_return(:body => response)
  else
    stub_request(:post, /amazonaws.com/).to_return(:body => response)
  end
end

def fake_response(xml)
  mock('RestClientFakeResponse', :body => xml)
end

Spec::Runner.configure do |config|

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rturk-2.10.3 spec/spec_helper.rb
rturk-2.10.2 spec/spec_helper.rb
rturk-2.10.1 spec/spec_helper.rb
rturk-2.10.0 spec/spec_helper.rb