On a cookbook I defined a class Rds::Checks that shares methods for building unix commands for bash/execute resources and Guards. A sample of the file libraries/checks.rb is:
module Rds
class Checks
class << self
def ssh_config_entry_present host, config_file, key_name
"cat #{config_file} | grep #{key_name}"
end
def redmine_migrated user, pass, name
"if [ `mysql -u#{user} -p#{pass} -e 'select count(id) FROM #{name}.users;' | sed -n '2 p'` -gt 0 ]; then echo '0'; else echo '1'; fi"
end
end
end
end
On LWPR providers, recipes and chefspec tests the file is loaded without problems, but when I use it inside serverspec through kitchen verify
it raise an error.
paolo@tower:~/cookbooks/rds$ cat test/integration/install/serverspec/localhost/install_spec.rb
...
it 'do migrations' do
cmd = Rds::Checks.redmine_migrated
expect(command(cmd).stdout).to eq 0
end
...
paolo@tower:~/cookbooks/rds$ kitchen verify
...
NameError:
uninitialized constant Rds
I would really like keep methods that builds bash/sh commands on a common layer so that I can test it separately and don't bother about them on unit and integration tests