Skip to content

Instantly share code, notes, and snippets.

@jeffmccune
Created July 23, 2012 20:46
Show Gist options
  • Save jeffmccune/3166129 to your computer and use it in GitHub Desktop.
Save jeffmccune/3166129 to your computer and use it in GitHub Desktop.
Mocha load order issue

Suite - Fails

jenkins@slave01:~/workspace/Puppet Module - stdlib (2.3.x)/facter/1.6.x/puppet/2.7.x/ruby/ruby-1.8.7/rvm/#rvm$ rspec -fd --order random:123 spec -d
/usr/lib/ruby/gems/1.8/gems/mocha-0.9.10/lib/mocha.rb:2
require 'mocha/options'
(rdb:1) e puts caller(0)
/usr/lib/ruby/gems/1.8/gems/mocha-0.9.10/lib/mocha.rb:2:in `gem_original_require'
/usr/lib/ruby/gems/1.8/gems/mocha-0.9.10/lib/mocha.rb:2:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/jenkins/workspace/Puppet Module - stdlib (2.3.x)/facter/1.6.x/puppet/2.7.x/ruby/ruby-1.8.7/rvm/#rvm/vendor/puppetlabs_spec_helper/lib/puppetlabs_spec_helper/puppet_spec_helper.rb:14
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/jenkins/workspace/Puppet Module - stdlib (2.3.x)/facter/1.6.x/puppet/2.7.x/ruby/ruby-1.8.7/rvm/#rvm/vendor/puppetlabs_spec_helper/lib/puppetlabs_spec_helper/module_spec_helper.rb:1
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/jenkins/workspace/Puppet Module - stdlib (2.3.x)/facter/1.6.x/puppet/2.7.x/ruby/ruby-1.8.7/rvm/#rvm/spec/spec_helper.rb:11
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/jenkins/workspace/Puppet Module - stdlib (2.3.x)/facter/1.6.x/puppet/2.7.x/ruby/ruby-1.8.7/rvm/#rvm/spec/unit/puppet/parser/functions/num2bool_spec.rb:2
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10
/usr/bin/rspec:19
nil
(rdb:1) l =
[-3, 5] in /usr/lib/ruby/gems/1.8/gems/mocha-0.9.10/lib/mocha.rb
   1  debugger
=> 2  require 'mocha/options'
   3  require 'mocha_standalone'
   4  require 'mocha/configuration'
   5  require 'mocha/integration'

Single File - Works

jenkins@slave01:~/workspace/Puppet Module - stdlib (2.3.x)/facter/1.6.x/puppet/2.7.x/ruby/ruby-1.8.7/rvm/#rvm$ rspec -fd --order random:123 -d spec/unit/puppet/parser/functions/get_module_path_spec.rb 
/usr/lib/ruby/gems/1.8/gems/mocha-0.9.10/lib/mocha.rb:2
require 'mocha/options'
(rdb:1) puts caller(0)
*** Unknown command: "puts caller(0)".  Try "help".
(rdb:1) irb
irb(main):001:0> puts caller(0)
(irb):1:in `gem_original_require'
/usr/lib/ruby/gems/1.8/gems/mocha-0.9.10/lib/mocha.rb:2:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/jenkins/workspace/Puppet Module - stdlib (2.3.x)/facter/1.6.x/puppet/2.7.x/ruby/ruby-1.8.7/rvm/#rvm/vendor/puppetlabs_spec_helper/lib/puppetlabs_spec_helper/puppet_spec_helper.rb:14
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/jenkins/workspace/Puppet Module - stdlib (2.3.x)/facter/1.6.x/puppet/2.7.x/ruby/ruby-1.8.7/rvm/#rvm/vendor/puppetlabs_spec_helper/lib/puppetlabs_spec_helper/module_spec_helper.rb:1
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/jenkins/workspace/Puppet Module - stdlib (2.3.x)/facter/1.6.x/puppet/2.7.x/ruby/ruby-1.8.7/rvm/#rvm/spec/spec_helper.rb:11
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/jenkins/workspace/Puppet Module - stdlib (2.3.x)/facter/1.6.x/puppet/2.7.x/ruby/ruby-1.8.7/rvm/#rvm/spec/unit/puppet/parser/functions/get_module_path_spec.rb:2
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10
/usr/bin/rspec:19
=> nil
(rdb:1) l =
[-3, 5] in /usr/lib/ruby/gems/1.8/gems/mocha-0.9.10/lib/mocha.rb
   1  debugger
=> 2  require 'mocha/options'
   3  require 'mocha_standalone'
   4  require 'mocha/configuration'
   5  require 'mocha/integration'

RSpec Puppet

This appears to be a load order issue with RSpec Puppet tests

For example, the parser function test fails if the RSpec Puppet test runs first:

+ rspec -fd -d spec/unit/puppet/provider/file_line/ruby_spec.rb spec/unit/puppet/parser/functions/get_module_path_spec.rb

Puppet::Type::File_line::ProviderRuby
  add
    should detect if the line exists in the file
    should detect if the line does not exist in the file
    should append to an existing file when creating
  remove
    should remove the line if it exists
    should remove the line without touching the last new line
    should remove any occurence of the line

function_get_module_path
  should only allow one argument
  should raise an exception when the module cannot be found
  when locating a module
    should be able to find module paths from the modulepath setting (FAILED - 1)
    should be able to find module paths when the modulepath is a list (FAILED - 2)
    should respect the environment (FAILED - 3)

Failures:

  1) function_get_module_path when locating a module should be able to find module paths from the modulepath setting
     Failure/Error: mod = mock("Puppet::Module")
     NoMethodError:
       undefined method `mock' for #
     # ./spec/unit/puppet/parser/functions/get_module_path_spec.rb:21
     # ./spec/unit/puppet/parser/functions/get_module_path_spec.rb:29

  2) function_get_module_path when locating a module should be able to find module paths when the modulepath is a list
     Failure/Error: mod = mock("Puppet::Module")
     NoMethodError:
       undefined method `mock' for #
     # ./spec/unit/puppet/parser/functions/get_module_path_spec.rb:21
     # ./spec/unit/puppet/parser/functions/get_module_path_spec.rb:34

  3) function_get_module_path when locating a module should respect the environment
     Failure/Error: mod = mock("Puppet::Module")
     NoMethodError:
       undefined method `mock' for #
     # ./spec/unit/puppet/parser/functions/get_module_path_spec.rb:21
     # ./spec/unit/puppet/parser/functions/get_module_path_spec.rb:40

Finished in 0.06278 seconds
11 examples, 3 failures

Failed examples:

rspec ./spec/unit/puppet/parser/functions/get_module_path_spec.rb:28 # function_get_module_path when locating a module should be able to find module paths from the modulepath setting
rspec ./spec/unit/puppet/parser/functions/get_module_path_spec.rb:32 # function_get_module_path when locating a module should be able to find module paths when the modulepath is a list
rspec ./spec/unit/puppet/parser/functions/get_module_path_spec.rb:37 # function_get_module_path when locating a module should respect the environment

However, if the parser function test runs first, they all pass:

+ rspec -fd -d spec/unit/puppet/parser/functions/get_module_path_spec.rb spec/unit/puppet/provider/file_line/ruby_spec.rb

function_get_module_path
  should only allow one argument
  should raise an exception when the module cannot be found
  when locating a module
    should be able to find module paths from the modulepath setting
    should be able to find module paths when the modulepath is a list
    should respect the environment

Puppet::Type::File_line::ProviderRuby
  add
    should detect if the line exists in the file
    should detect if the line does not exist in the file
    should append to an existing file when creating
  remove
    should remove the line if it exists
    should remove the line without touching the last new line
    should remove any occurence of the line

Finished in 0.18329 seconds
11 examples, 0 failures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment