envato / ami-spec

Acceptance testing your AMIs
MIT License
49 stars 15 forks source link

Using `:if` in context/describe declaration causes an exception to be thrown by SpecInfra #22

Closed patrobinson closed 8 years ago

patrobinson commented 8 years ago

If you don't set :ssh_options for ServerSpec, it throws an exception

 `sudo?': undefined method `[]' for nil:NilClass (NoMethodError)

We set the :ssh_options when calling AmiSpec::ServerSpec.run, because the values of this are unknown until runtime.

SpecInfra wants to evaluate the conditional at load time, not at run time.

Stack trace:

./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/backend/ssh.rb:179:in `sudo?': undefined method `[]' for nil:NilClass (NoMethodError)
    from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/backend/ssh.rb:42:in `build_command'
    from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/backend/ssh.rb:10:in `run_command'
    from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/detect_os.rb:13:in `run_command'
    from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/detect_os/freebsd.rb:3:in `detect'
    from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/detect_os.rb:5:in `detect'
    from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/os.rb:24:in `block in detect_os'
    from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/os.rb:23:in `each'
    from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/os.rb:23:in `detect_os'
    from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/os.rb:9:in `os'