Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`add_test': undefined method error on Ubuntu 15.10 with Ruby 2.1 #642

Closed
gregelin opened this issue Apr 15, 2016 · 5 comments
Closed

`add_test': undefined method error on Ubuntu 15.10 with Ruby 2.1 #642

gregelin opened this issue Apr 15, 2016 · 5 comments
Labels
Type: Bug Feature not working as expected

Comments

@gregelin
Copy link

Description

Created simple example test.rb using code from README (see below). Ran inspec exec test.rb and received an error with stack trace when I expected to see the tests executed and results.

InSpec and Platform Version

Distributor ID: Ubuntu
Description: Ubuntu 15.10
Release: 15.10
Codename: wily

Replication Case

  1. Install Ruby, Ruby-Dev, InSpec on Ubuntu (see Install failed on Ubuntu with Ruby 2.1 #641)
  2. Create simple test.rb using example from README
  3. Run inspec exec test.rb

Possible Solutions

Tested similar steps on OS X and test.rb executed as expected. So we know syntax of test.rb OK.

Is Ruby version 2.1 a problem?

Stacktrace

root@kbs:~# mkdir inspec_test
root@kbs:~# cd inspec_test/
root@kbs:~/inspec_test# vi test.rb
root@kbs:~/inspec_test# inspec exec test.rb 
/var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/inspec/runner_rspec.rb:51:in `add_test': undefined method `register' for #<RSpec::Core::World:0x00000002c79e88> (NoMethodError)
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/inspec/runner.rb:183:in `block in register_rule'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/inspec/runner.rb:174:in `each'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/inspec/runner.rb:174:in `register_rule'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/inspec/runner.rb:104:in `block in add_content'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/inspec/runner.rb:103:in `each'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/inspec/runner.rb:103:in `add_content'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/inspec/runner.rb:68:in `add_profile'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/inspec/runner.rb:52:in `add_target'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/utils/base_cli.rb:69:in `block in run_tests'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/utils/base_cli.rb:69:in `each'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/utils/base_cli.rb:69:in `run_tests'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/lib/inspec/cli.rb:113:in `exec'
    from /var/lib/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /var/lib/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /var/lib/gems/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /var/lib/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /var/lib/gems/2.1.0/gems/inspec-0.18.0/bin/inspec:9:in `<top (required)>'
    from /usr/local/bin/inspec:23:in `load'
    from /usr/local/bin/inspec:23:in `<main>'

root@kbs:~/inspec_test# cat test.rb 
describe package('telnetd') do
  it { should_not be_installed }
end

describe inetd_conf do
  its("telnet") { should eq nil }
end
@srenatus
Copy link
Contributor

Hmm curious case. Thanks for reporting. Could you share the output of gem list rspec, please?

@mafr
Copy link

mafr commented Apr 16, 2016

Same error here on Ubuntu 15.10 with ruby 2.1.5p273.

$ gem list rspec

*** LOCAL GEMS ***

rspec (3.5.0.beta3)
rspec-core (3.5.0.beta3)
rspec-expectations (3.5.0.beta3)
rspec-its (1.2.0)
rspec-mocks (3.5.0.beta3)
rspec-support (3.5.0.beta3)
$ 

@chris-rock chris-rock added the Type: Bug Feature not working as expected label Apr 16, 2016
@chris-rock
Copy link
Contributor

chris-rock commented Apr 16, 2016

I just tried this on a new ubuntu wily box (vagrant). I had no troubles installing inspec:

root@vagrant-ubuntu-wily-64:~# cat test.rb 
describe package('telnetd') do
  it { should_not be_installed }
end

describe inetd_conf do
  its("telnet") { should eq nil }
end
root@vagrant-ubuntu-wily-64:~# gem list rspec

*** LOCAL GEMS ***

rspec (3.3.0)
rspec-core (3.3.0)
rspec-expectations (3.3.0)
rspec-its (1.2.0)
rspec-mocks (3.3.0)
rspec-support (3.3.0)
serverspec (2.18.0)
root@vagrant-ubuntu-wily-64:~# ruby -v
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]
root@vagrant-ubuntu-wily-64:~# inspec version
0.18.0
root@vagrant-ubuntu-wily-64:~# inspec exec test.rb 
..

Finished in 0.04281 seconds (files took 0.42523 seconds to load)
2 examples, 0 failures

Therefore its not a ruby 2.1 issue, since we tests this regularly.
@gregelin could you share your ruby and rspec versions?
@mafr How come that you have the rspec beta gems installed?

@mafr
Copy link

mafr commented Apr 16, 2016

There was nothing Ruby-related on my machine and I was just following instructions :)

I end up with beta versions of rspec reliably - here's how to reproduce this in Docker:

$ docker run -ti ubuntu:15.10 /bin/bash
root@df713ab9e02d:/# apt-get update && apt-get install -y ruby ruby-dev gcc make
[...]
root@df713ab9e02d:/# gem install inspec
[...]
root@df713ab9e02d:/# cat > test.rb
describe package('telnetd') do
  it { should_not be_installed }
end

describe inetd_conf do
  its("telnet") { should eq nil }
end
root@df713ab9e02d:/# inspec exec test.rb
[ error as posted ]
root@df713ab9e02d:/# gem list rspec

*** LOCAL GEMS ***

rspec (3.5.0.beta3)
rspec-core (3.5.0.beta3)
rspec-expectations (3.5.0.beta3)
rspec-its (1.2.0)
rspec-mocks (3.5.0.beta3)
rspec-support (3.5.0.beta3)
root@df713ab9e02d:/#

When running "gem install rspec", I get version 3.4.0, but via "gem install inspec", I end up with the beta versions. Downgrading to rspec 3.4.0 fixes the problem, BTW.

@chris-rock
Copy link
Contributor

In addition we also added support for our own docker container in #649

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

No branches or pull requests

4 participants