Sha256: 1516202d17fe6813e3371696a080e87010ac0c28f7f4c274a3b4beb38ae4af94

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe RTurk::Requester do

  before(:all) do
    WebMock.reset!
    aws = YAML.load(File.open(File.join(SPEC_ROOT, 'mturk.yml')))
    RTurk.setup(aws['AWSAccessKeyId'], aws['AWSAccessKey'], :sandbox => true)
  end

  it "should send the request to Amazon" do
    RestClient.should_receive(:post).with(/amazonaws/, /Operation=GetHIT.*$/)
    RTurk::Requester.request(:Operation => 'GetHIT', 'HITId' => 'test')
  end

  it "should build a correct querystring with one value per key" do
    params = {
      :Operation => 'GetHIT',
      'Param1' => 'test1',
      'Param2' => 'test2'
    }
    RestClient.should_receive(:post).with(
      /amazonaws/,
      /(?=.*Operation=GetHIT)(?=.*Param1=test1)(?=.*Param2=test2)/)
    RTurk::Requester.request(params)
  end

  it "should build a correct querystring with two values per key" do
    params = {
      :Operation => 'GetHIT',
      'Param1' => 'test1',
      'Param2' => %w(test2a test2b)
    }
    RestClient.should_receive(:post).with(
      /amazonaws/,
      /(?=.*Operation=GetHIT)(?=.*Param1=test1)(?=.*Param2=test2a)(?=.*Param2=test2b)/)
    RTurk::Requester.request(params)
  end

  it "should build a correct querystring with a hash of values" do
    params = {
      :Operation => 'GetHIT',
      'Param1' => 'test1',
      'Param2' => {0 => 'test2a', 1 => 'test2b'}
    }
    RestClient.should_receive(:post).with(
      /amazonaws/,
      /(?=.*Operation=GetHIT)(?=.*Param1=test1)(?=.*Param2.0=test2a)(?=.*Param2.1=test2b)/)
    RTurk::Requester.request(params)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rturk-2.6.0 spec/requester_spec.rb
rturk-2.5.2 spec/requester_spec.rb
rturk-2.5.0 spec/requester_spec.rb
rturk-2.4.1 spec/requester_spec.rb
rturk-2.4.0 spec/requester_spec.rb