Skip to content

Instantly share code, notes, and snippets.

@joestump
Last active January 1, 2016 00:19
Show Gist options
  • Save joestump/045969db1928537807d9 to your computer and use it in GitHub Desktop.
Save joestump/045969db1928537807d9 to your computer and use it in GitHub Desktop.
(sprint.ly)Joes-MacBook-Air:rstudio-chef jstump$ bundle exec rake
/usr/local/Cellar/ruby/2.0.0-p353/bin/ruby -S rspec ./spec/server_spec.rb
chefspec
FF
Failures:
1) rstudio::server should install r-base
Failure/Error: expect(chef_run).to install_package('r-base')
expected "package[r-base] with" action :install to be in Chef run. Other package resources:
# ./spec/server_spec.rb:19:in `block (2 levels) in <top (required)>'
2) rstudio::server should install rstudio-server
Failure/Error: expect(chef_run).to install_package('rstudio-server')
NoMethodError:
undefined method `resource_collection' for nil:NilClass
# ./spec/server_spec.rb:23:in `block (2 levels) in <top (required)>'
Finished in 1.51 seconds
2 examples, 2 failures
Failed examples:
rspec ./spec/server_spec.rb:15 # rstudio::server should install r-base
rspec ./spec/server_spec.rb:22 # rstudio::server should install rstudio-server
/usr/local/Cellar/ruby/2.0.0-p353/bin/ruby -S rspec ./spec/server_spec.rb failed
puts node["platform"]
# Set up the package repository.
case node["platform"].downcase
when "ubuntu", "debian"
include_recipe "apt"
apt_repository "rstudio-cran" do
uri node['rstudio']['apt']['uri']
keyserver node['rstudio']['apt']['keyserver']
key node['rstudio']['apt']['key']
distribution "#{node['lsb']['codename']}/"
end
package "r-base" do
action :install
end
package "rstudio-server" do
action :install
end
end
service "rstudio-server" do
provider Chef::Provider::Service::Upstart
supports :start => true, :stop => true, :restart => true
action :start
end
template "/etc/rstudio/rserver.conf" do
source "etc/rstudio/rserver.conf.erb"
mode 0644
owner "root"
group "root"
notifies :restart, resources(:service => "rstudio-server")
end
template "/etc/rstudio/rsession.conf" do
source "etc/rstudio/rsession.conf.erb"
mode 0644
owner "root"
group "root"
notifies :restart, resources(:service => "rstudio-server")
end
require 'spec_helper'
describe 'rstudio::server' do
let(:chef_run) do
# ChefSpec::Runner.new do |node|
# node.set['lsb']['codename'] = 'ubuntu'
# end.converge(described_recipe)
ChefSpec::Runner.new
end
before do
Fauxhai.mock(platform: 'ubuntu', version: '12.04')
end
it('should install r-base') do
# chef_run.node.set['cookbook']['attribute'] = 'hello'
chef_run.node.set['platform'] = 'ubuntu'
chef_run.converge(described_recipe)
expect(chef_run).to install_package('r-base')
end
it('should install rstudio-server') do
expect(chef_run).to install_package('rstudio-server')
end
end
@sethvargo
Copy link

Set those attributes in the runner:

ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04').new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment