Skip to content

When requiring the Ruby's timeout library I can no longer retrieve a nested attribute named timeout on an OpenStruct #56

@burtlo

Description

@burtlo

The wrapper class here is a quick example of the behavior. While the example does not use the timeout library methods it is present in a larger project I am currently working on.

Given this yaml file:

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

And a test file:

require 'ostruct'
require 'yaml'
require 'timeout'
require 'rspec/its'

class DatabaseConfg
  def development
    hash = YAML.load(File.read('database.yml'))
    struct = OpenStruct.new(hash['development'])
  end
end

describe DatabaseConfg do
  its('development.database') { should eq 'db/development.sqlite3' }
  its('development.timeout') { should eq 5000 }
end

When I execute the tests I see an error that is the same error if you ran timeout without any parameters

$ rspec example_spec.rb
./usr/local/var/rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rspec-its-1.2.0/lib/rspec/its.rb:115:in `block (3 levels) in its': Object#timeout is deprecated, use Timeout.timeout instead.
F

Failures:

  1) DatabaseConfg development.timeout
     Failure/Error: its('development.timeout') { should eq 5000 }

     ArgumentError:
       wrong number of arguments (given 0, expected 1..3)
     # ./rspec_example_spec.rb:15:in `block (2 levels) in <top (required)>'

Finished in 0.00413 seconds (files took 0.13378 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ./rspec_example_spec.rb:15 # DatabaseConfg development.timeout

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions