class Object

Constants

APP_PATH

This command will automatically be run when you run “rails” with Rails 3 gems installed from the root of your application.

Public Instance Methods

create_bucket_high_level(options = {}) click to toggle source
# File features/support/common.rb, line 155
def create_bucket_high_level options = {}
  @bucket_name = options.delete(:name) || "ruby-integration-test-#{Time.now.to_i}"
  @endpoint = @s3.client.config.s3_endpoint
  @bucket = @s3.buckets.create(@bucket_name, options)
  @buckets_created << [@bucket_name, @endpoint]
  @bucket
end
create_bucket_low_level(options = {}) click to toggle source

helpers for creating domains / buckets in a way that they will get cleaned up

# File features/support/common.rb, line 146
def create_bucket_low_level options = {}
  options[:bucket_name] ||= "ruby-integration-test-#{Time.now.to_i}"
  @bucket_name = options[:bucket_name]
  @endpoint = options[:endpoint] || @s3_client.config.s3_endpoint
  @result = @s3_client.create_bucket(options)
  @buckets_created << [@bucket_name, @endpoint]
  sleep 0.5 # Dumb insurance against eventual consistency
end
create_domain_high_level(name = nil) click to toggle source
# File features/support/common.rb, line 171
def create_domain_high_level name = nil
  @domain_name = name || "ruby-integration-test-#{Time.now.to_i}"
  @endpoint = @sdb.client.config.simple_db_endpoint
  @domain = @sdb.domains.create(@domain_name)
  @sdb_domains_created << [@domain_name, @endpoint]
end
create_domain_low_level(options = {}) click to toggle source
# File features/support/common.rb, line 163
def create_domain_low_level options = {}
  @domain_name = options[:domain_name]
  @endpoint = options.delete(:endpoint) || @sdb_client.config.simple_db_endpoint
  @response = @sdb_client.with_options(:simple_db_endpoint => @endpoint).
    create_domain(options)
  @sdb_domains_created << [@domain_name, @endpoint]
end
create_virtual_mfa_device(options = {}) click to toggle source

Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the “License”). You may not use this file except in compliance with the License. A copy of the License is located at

http://aws.amazon.com/apache2.0/

or in the “license” file accompanying this file. This file is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

# File features/iam/step_definitions/mfa.rb, line 14
def create_virtual_mfa_device(options = {})
  name = "RubyTest-#{Time.now.to_f}"
  @result = @mfa_device = @iam.virtual_mfa_devices.create(name, options)
  @created_mfa_devices << @mfa_device
end
eventually(seconds = 60*5) { || ... } click to toggle source
# File features/support/common.rb, line 178
def eventually(seconds = 60*5)
  sleeps = [1]
  while sleeps.inject(0) { |sum, i| sum + i } < seconds
    sleeps << sleeps.last * 1.2
  end
  request_count = (@http_handler.requests_made || []).size
  begin
    yield
  rescue => e
    unless sleeps.empty? or
        # no additional requests were made, it's probably a coding error
        # in the test
        request_count == (@http_handler.requests_made || []).size
      sleep(sleeps.shift)
      request_count = (@http_handler.requests_made || []).size
      retry
    end
    raise e
  end
end
execute_post(form, opts = {}) click to toggle source
# File features/s3/high_level/step_definitions/post.rb, line 121
def execute_post(form, opts = {})
  require 'net/http/post/multipart'

  data = opts[:data] || "HELLO"
  filename = opts[:filename] || "foo.txt"

  Net::HTTP.start(form.url.host) do |http|
    file = UploadIO.new(StringIO.new(data), "text/plain", filename)

    fields = form.fields.
      merge(opts[:additional] || {})
    fields["key"] ||= "foo"

    fields = fields.to_a + [["file", file]]

    req = Net::HTTP::Post::Multipart.new(form.url.path, fields)
    resp = http.request(req)
    @result = resp

    unless 
      resp.kind_of?(Net::HTTPSuccess) or 
      resp.kind_of?(Net::HTTPRedirection) or
      resp.kind_of?(Net::HTTPForbidden)
    then
      raise "status code #{resp.code}: #{resp.body}"
    end

  end
end
get_bucket() click to toggle source
# File features/s3/low_level/step_definitions/buckets.rb, line 16
def get_bucket
  Net::HTTP.get(URI.parse("http://#{@endpoint}/#{@bucket_name}/"))
end
get_session(pool) click to toggle source
# File spec/net/http/connection_pool_spec.rb, line 122
def get_session pool
  a_session = nil
  pool.send(:session_for,connection) do |session|
    a_session = session
  end
  a_session
end
ip_ranges_from_table(table) click to toggle source
# File features/ec2/step_definitions/security_groups.rb, line 79
def ip_ranges_from_table table
  table.hashes.select{|r| r['type'] == 'ip_range'}.collect{|r| r['value'] }
end
meta_hash(table) click to toggle source
# File features/s3/high_level/step_definitions/objects.rb, line 171
def meta_hash table
  table.hashes.inject({}) {|d,h| d[h['key']] = h['value']; d }
end
requests_matching(requests, table) click to toggle source
# File features/step_definitions.rb, line 124
def requests_matching requests, table
  matched = []
  requests.each do |request|

    catch(:non_matching) do

      table.hashes.each do |requirement|

        (type, name, value) = requirement.values_at('TYPE', 'NAME', 'VALUE')

        case type
        when 'http'
          throw :non_matching unless
            case name
            when 'verb'       then request.http_method == value
            when 'host'       then request.host == value
            when 'host_match' then request.host =~ %r^#{value}$/
            when 'path'       then request.path == value
            when 'path_match' then request.path =~ %r^#{value}$/
            when 'uri'        then request.uri == value
            when 'uri_match'  then request.uri =~ %r^#{value}$/
            when 'body'       then request.body == value
            else pending("unhandled http requirement `#{name}`")
            end

        when 'param'
          throw :non_matching unless begin
            param = request.params.detect{|p| p.name == name }
            param and param.value.to_s == value
          end

        when 'param_match'
          throw :non_matching unless begin
            param = request.params.detect{|p| p.name == name }
            param and param.value.to_s =~ %r^#{value}$/
          end

        when 'header'
          throw :non_matching unless request.headers[name].to_s == value

        when 'header_match'
          throw :non_matching unless request.headers[name].to_s =~ %r^#{value}$/

        when 'json'
          body = JSON.load(request.body)
          throw :non_matching unless
            (eval("body#{name}").to_s == value rescue false)

        when 'json_match'
          body = JSON.load(request.body)
          throw :non_matching unless
            (eval("body#{name}").to_s =~ %r^#{value}$/ rescue false)

        when 'target'
          if name == 'like'
            throw :non_matching unless request.headers['x-amz-target'] =~ %r#{value}/
          else
            throw :non_matching unless request.headers['x-amz-target'] == value
          end

        else pending("unhandled requirement type `#{type}`")
        end

      end

      matched << request

    end
  end
  matched
end
security_groups_from_table(table, owner_id) click to toggle source
# File features/ec2/step_definitions/security_groups.rb, line 83
def security_groups_from_table table, owner_id
  names = table.hashes.select{|r| r['type'] == 'group'}.collect{|r| r['value'] }
  @ec2.security_groups.filter('group-name', *names).to_a
end
stub_config() click to toggle source

Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the “License”). You may not use this file except in compliance with the License. A copy of the License is located at

http://aws.amazon.com/apache2.0/

or in the “license” file accompanying this file. This file is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

# File spec/shared/stub_config_examples.rb, line 14
def stub_config
  AWS::Core::Configuration.new({
    :stub_requests => true,
    :access_key_id => 'ACCESS_KEY_ID',
    :secret_access_key => 'SECRET_ACCESS_KEY',
    :session_token => 'SESSION_TOKEN'
  })
end
table_formatted_requests(requests) click to toggle source
# File features/step_definitions.rb, line 196
def table_formatted_requests requests
#   tables = requests.collect do |req| 
#     table = []
#     table << "|TYPE|NAME|VALUE|"
#     table << "|http|verb|#{req.http_method}|"
#     table << "|http|host|#{req.host}|"
#     table << "|http|path|#{req.path}|"
#     table << "|http|uri|#{req.uri}|"
#     req.params.each do |param|
#       # EEEK! this will likely need to change at some point, we have to remove
#       # the newlines because that makes for an invalid table
#       table << "|param|#{param.name}|#{param.value.gsub(/\n/, '')}|"
#     end
#     req.headers.each_pair do |key,value|
#       #unless %w(authorization date).include?(key)
#         table << "|param|#{key}|#{value}|"
#       #end
#     end
#     Cucumber::Ast::Table.parse(table.join("\n"), nil, nil)
#   end
#   tables.collect{|t| t.to_s(:color => false, :prefixes => Hash.new('')) }
  tables = requests.collect do |req| 
    table = []
    if req.headers["content-type"].include?("json")
      table << %w(TYPE NAME VALUE)
      table << ['header', 'x-amz-target', req.headers["x-amz-target"]]
      body = JSON.load(req.body)
      body.each do |name, value|
        table << ['json', "[\"#{name}\"]", value.inspect]
      end
    else
      table << %w(TYPE NAME VALUE)
      table << ['http', 'verb', req.http_method.to_s]
      table << ['http', 'host', req.host.to_s]
      table << ['http', 'path', req.path.to_s]
      table << ['http', 'uri', req.uri.to_s]
      req.params.each do |param|
        table << ['param', param.name.to_s, param.value.to_s]
      end
      req.headers.each_pair do |key,value|
        table << ['header', key.to_s, value.to_s]
      end
    end
    Cucumber::Ast::Table.new(table)
  end
  tables.collect{|t| t.to_s(:color => false, :prefixes => Hash.new('')) }
end
tempfile(contents) { |f| ... } click to toggle source
# File features/support/common.rb, line 199
def tempfile(contents)
  f = Tempfile.new("aws-sdk-cucumber")
  path = f.path
  f.close
  f.unlink
  File.open(path, "w+b") do |f|
    f.write(contents)
    f.flush
    yield(f)
  end
end
unless_blank(value) { |value| ... } click to toggle source

Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the “License”). You may not use this file except in compliance with the License. A copy of the License is located at

http://aws.amazon.com/apache2.0/

or in the “license” file accompanying this file. This file is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

# File recipebook/config/initializers/monkey_patch.rb, line 14
def unless_blank value, &block
  unless value.blank?
    return yield(value)
  end
  nil
end
valid_policy() click to toggle source

Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the “License”). You may not use this file except in compliance with the License. A copy of the License is located at

http://aws.amazon.com/apache2.0/

or in the “license” file accompanying this file. This file is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

# File features/s3/low_level/step_definitions/policies.rb, line 14
def valid_policy; "{ "Id": "Policy1296685811282",
  "Version": "2008-10-17",
      "Statement": [
        {
          "Sid": "Stmt1296685809629",
          "Action": "s3:*",
          "Effect": "Allow",
          "Resource": "arn:aws:s3:::#@bucket_name",
          "Principal": {
            "AWS": "arn:aws:iam::681294939609:root"
          }
        }
      ]
    }
"; end