Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Migrated test suite from test/unit to rspec

  • Loading branch information...
commit 91fa76ef3a5028e38182e8a79d0470aa76b48a05 1 parent ac60ea8
@technicalpickles technicalpickles authored
Showing with 1,106 additions and 906 deletions.
  1. +2 −2 .gitignore
  2. +7 −8 Rakefile
  3. +123 −0 spec/moonshine/manifest/apache_spec.rb
  4. +435 −0 spec/moonshine/manifest/rails_spec.rb
  5. +190 −0 spec/moonshine/manifest_spec.rb
  6. +101 −0 spec/moonshine_generator_spec.rb
  7. +15 −14 test/test_moonshine_plugin_generator.rb → spec/moonshine_plugin_generator_spec.rb
  8. +11 −0 spec/pathname_spec.rb
  9. 0  {test → spec}/rails_root/config/database.yml
  10. 0  {test → spec}/rails_root/config/moonshine.yml
  11. 0  {test → spec}/rails_root/config/moonshine/test.yml
  12. 0  {test → spec}/rails_root/vendor/plugins/moonshine_eval_test/moonshine/init.rb
  13. +15 −12 test/test_rails_setup.rb → spec/rails_setup_spec.rb
  14. +2 −0  spec/spec.opts
  15. +18 −0 spec/spec_helper.rb
  16. +31 −0 spec/support/moonshine_helpers.rb
  17. +136 −0 spec/support/moonshine_matchers.rb
  18. +20 −0 spec/support/rails_2_generator_kludge.rb
  19. +0 −117 test/moonshine/manifest/test_apache.rb
  20. +0 −369 test/moonshine/manifest/test_rails.rb
  21. +0 −182 test/moonshine/test_manifest.rb
  22. +0 −16 test/support/rails_2_generator_kludge.rb
  23. +0 −71 test/test_helper.rb
  24. +0 −104 test/test_moonshine_generator.rb
  25. +0 −11 test/test_pathname.rb
View
4 .gitignore
@@ -4,5 +4,5 @@ rdoc
doc
coverage
.autotest
-test/test.log
-test/generator.log
+spec/test.log
+spec/generator.log
View
15 Rakefile
@@ -11,14 +11,13 @@ task :rcov do
system "rcov --exclude /Library/Ruby/ --exclude ~/ -Itest `find test/ | grep _test`"
end
-desc 'Default: run unit tests.'
-task :default => :test
-
-desc 'Test the moonshine plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'test'
- t.pattern = 'test/**/test_*.rb'
- t.verbose = true
+desc 'Default: specs'
+task :default => :spec
+
+require 'spec/rake/spectask'
+desc "Run all specs in spec directory (excluding plugin specs)"
+Spec::Rake::SpecTask.new do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
end
desc 'Generate documentation for the moonshine plugin.'
View
123 spec/moonshine/manifest/apache_spec.rb
@@ -0,0 +1,123 @@
+require 'spec_helper'
+
+describe Moonshine::Manifest::Rails::Apache do
+ before do
+ @manifest = Moonshine::Manifest::Rails.new
+ end
+
+ it "provides a default configuration" do
+ @manifest.apache_server
+
+ apache2_conf_content = @manifest.files['/etc/apache2/apache2.conf'].content
+
+ @manifest.configuration[:apache].should be_kind_of(Hash)
+
+ @manifest.configuration[:apache][:keep_alive].should == 'Off'
+ apache2_conf_content.should have_apache_directive('KeepAlive', 'Off')
+
+ @manifest.configuration[:apache][:max_keep_alive_requests].should == 100
+ apache2_conf_content.should have_apache_directive('MaxKeepAliveRequests', 100)
+
+ @manifest.configuration[:apache][:keep_alive_timeout].should == 15
+ apache2_conf_content.should have_apache_directive('KeepAliveTimeout', 15)
+
+ @manifest.configuration[:apache][:max_clients].should == 150
+ apache2_conf_content.should have_apache_directive('MaxClients', 150)
+
+ @manifest.configuration[:apache][:server_limit].should == 16
+ apache2_conf_content.should have_apache_directive('ServerLimit', 16)
+
+ @manifest.configuration[:apache][:timeout].should == 300
+ apache2_conf_content.should have_apache_directive('Timeout', 300)
+ end
+
+ it "allows configuration to be overriden early" do
+ @manifest.configure :apache => {
+ :keep_alive => 'On',
+ :max_keep_alive_requests => 200,
+ :keep_alive_timeout => 30,
+ :max_clients => 300,
+ :server_limit => 32,
+ :timeout => 600
+ }
+ @manifest.apache_server
+
+ apache2_conf_content = @manifest.files['/etc/apache2/apache2.conf'].content
+
+ @manifest.configuration[:apache][:timeout].should == 600
+ apache2_conf_content.should have_apache_directive('Timeout', 600)
+
+ @manifest.configuration[:apache][:keep_alive].should == 'On'
+ apache2_conf_content.should have_apache_directive('KeepAlive', 'On')
+
+ @manifest.configuration[:apache][:max_keep_alive_requests].should == 200
+ apache2_conf_content.should have_apache_directive('MaxKeepAliveRequests', 200)
+
+ @manifest.configuration[:apache][:keep_alive_timeout].should == 30
+ apache2_conf_content.should have_apache_directive('KeepAliveTimeout', 30)
+
+ in_apache_if_module apache2_conf_content, 'mpm_worker_module' do |mpm_worker_module|
+ @manifest.configuration[:apache][:max_clients].should == 300
+ mpm_worker_module.should have_apache_directive('MaxClients', 300)
+
+ @manifest.configuration[:apache][:server_limit].should == 32
+ mpm_worker_module.should have_apache_directive('ServerLimit', 32)
+ end
+
+ end
+
+ it "allows configuration to be overriden late" do
+ @manifest.apache_server
+ @manifest.configure :apache => { :keep_alive => 'On' }
+
+ apache2_conf_content = @manifest.files['/etc/apache2/apache2.conf'].content
+
+ @manifest.configuration[:apache][:keep_alive].should == 'On'
+ apache2_conf_content.should have_apache_directive('KeepAlive', 'On')
+ end
+
+ it "defaults KeepAlive to Off" do
+ @manifest.apache_server
+
+ apache2_conf_content = @manifest.files['/etc/apache2/apache2.conf'].content
+
+ pending "seems to be some weird load-order thing causing this to fail"
+ apache2_conf_content.should have_apache_directive('KeepAlive', 'Off')
+ end
+
+ it "starts apache2" do
+ @manifest.apache_server
+
+ # TODO refactor to something like @manifest.should have_service('apache2').require(package('apache2-mpm-worker'))
+ apache = @manifest.services["apache2"]
+ apache.should_not == nil
+ apache.require.to_s.should == @manifest.package('apache2-mpm-worker').to_s
+ end
+
+ it "supports ssl" do
+ @manifest.configure(:ssl => {
+ :certificate_file => 'cert_file',
+ :certificate_key_file => 'cert_key_file',
+ :certificate_chain_file => 'cert_chain_file'
+ })
+
+ @manifest.apache_server
+
+ @manifest.should exec_command('/usr/sbin/a2enmod ssl')
+ end
+
+ it "enables mod_rewrite" do
+ @manifest.apache_server
+
+ @manifest.should exec_command('/usr/sbin/a2enmod rewrite')
+ end
+
+ it "enables mod_status" do
+ @manifest.apache_server
+
+ @manifest.should exec_command('/usr/sbin/a2enmod status')
+ @manifest.should have_file("/etc/apache2/mods-available/status.conf").with_content(
+ /127.0.0.1/
+ )
+ end
+end
View
435 spec/moonshine/manifest/rails_spec.rb
@@ -0,0 +1,435 @@
+require 'spec_helper'
+
+# mock out the gem source index to fake like passenger is installed, but
+# nothing else
+module Gem #:nodoc:
+ class SourceIndex #:nodoc:
+ alias_method :orig_search, :search
+ def search(gem_pattern, platform_only = false)
+ if gem_pattern.name.to_s =~ /passenger/
+ orig_search(gem_pattern, platform_only)
+ else
+ []
+ end
+ end
+ end
+end
+
+describe Moonshine::Manifest::Rails do
+
+ before do
+ @manifest = subject
+ end
+
+ it { should be_executable }
+
+ context "default_stack" do
+ it "supports mysql" do
+ @manifest.should_receive(:database_environment).at_least(:once).and_return({:adapter => 'mysql'})
+
+ @manifest.default_stack
+
+ @manifest.should use_recipe(:apache_server)
+ @manifest.should use_recipe(:passenger_gem)
+ @manifest.should use_recipe(:passenger_configure_gem_path)
+ @manifest.should use_recipe(:passenger_apache_module)
+ @manifest.should use_recipe(:passenger_site)
+
+ @manifest.should use_recipe(:mysql_server)
+ @manifest.should use_recipe(:mysql_gem)
+ @manifest.should use_recipe(:mysql_database)
+ @manifest.should use_recipe(:mysql_user)
+ @manifest.should use_recipe(:mysql_fixup_debian_start)
+
+ @manifest.should use_recipe(:rails_rake_environment)
+ @manifest.should use_recipe(:rails_gems)
+ @manifest.should use_recipe(:rails_directories)
+ @manifest.should use_recipe(:rails_bootstrap)
+ @manifest.should use_recipe(:rails_migrations)
+ @manifest.should use_recipe(:rails_logrotate)
+
+ @manifest.should use_recipe(:ntp)
+ @manifest.should use_recipe(:time_zone)
+ @manifest.should use_recipe(:postfix)
+ @manifest.should use_recipe(:cron_packages)
+ @manifest.should use_recipe(:motd)
+ @manifest.should use_recipe(:security_updates)
+
+ end
+
+ it "supports postgresl" do
+ @manifest.should_receive(:database_environment).at_least(:once).and_return({:adapter => 'postgresql' })
+
+ @manifest.default_stack
+
+ @manifest.should use_recipe(:postgresql_server)
+ @manifest.should use_recipe(:postgresql_gem)
+ @manifest.should use_recipe(:postgresql_user)
+ @manifest.should use_recipe(:postgresql_database)
+ end
+
+ it "supports sqlite3" do
+ @manifest.should_receive(:database_environment).at_least(:once).and_return({:adapter => 'sqlite' })
+
+ @manifest.default_stack
+
+ @manifest.should use_recipe(:sqlite3)
+ end
+ end
+
+ specify "#security_update" do
+ @manifest.configure(:unattended_upgrade => { :package_blacklist => ['foo', 'bar', 'widget']})
+ @manifest.configure(:user => 'rails')
+
+ @manifest.security_updates
+
+ @manifest.should have_package("unattended-upgrades")
+ @manifest.should have_file("/etc/apt/apt.conf.d/10periodic").with_content(
+ /APT::Periodic::Unattended-Upgrade "1"/
+ )
+ @manifest.should have_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content(
+ /Unattended-Upgrade::Mail "rails@localhost";/
+ )
+ @manifest.should have_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content(
+ /"foo";/
+ )
+ end
+
+ describe "#rails_gems" do
+ it "configures gem sources" do
+ @manifest.rails_gems
+
+ @manifest.should have_file('/etc/gemrc').with_content(
+ /gems.github.com/
+ )
+ end
+
+ it "loads gems from config" do
+ @manifest.configure(:gems => [ { :name => 'jnewland-pulse', :source => 'http://gems.github.com' } ])
+ @manifest.rails_gems
+
+ Moonshine::Manifest::Rails.configuration[:gems].should_not be_nil
+
+ Moonshine::Manifest::Rails.configuration[:gems].each do |gem|
+ @manifest.should have_package(gem[:name]).from_provider(:gem)
+ end
+ @manifest.packages['jnewland-pulse'].source.should be_nil
+ end
+
+ it "magically loads gem dependencies" do
+ @manifest.configure(:gems => [
+ { :name => 'webrat' },
+ { :name => 'thoughtbot-paperclip', :source => 'http://gems.github.com' }
+ ])
+
+ @manifest.rails_gems
+
+ @manifest.should have_package('webrat')
+ @manifest.should have_package('thoughtbot-paperclip')
+ @manifest.should have_package('libxml2-dev')
+ @manifest.should have_package('imagemagick')
+ end
+
+ end
+
+ it "cretes directories" do
+ config = {
+ :application => 'foo',
+ :user => 'foo',
+ :deploy_to => '/srv/foo'
+ }
+ @manifest.configure(config)
+
+ @manifest.rails_directories
+
+
+ shared_dir = @manifest.files["/srv/foo/shared"]
+ shared_dir.should_not be_nil
+ shared_dir.ensure.should == :directory
+ shared_dir.owner.should == 'foo'
+ shared_dir.group.should == 'foo'
+ end
+
+ describe "passenger support" do
+ it "installs gem" do
+ @manifest.configure(:passenger => { :version => nil })
+
+ @manifest.passenger_configure_gem_path
+ @manifest.passenger_gem
+
+ @manifest.should have_package('passenger').version(:latest)
+ end
+
+ it "can be pinned to a specific version" do
+ @manifest.configure(:passenger => { :version => '2.2.2' })
+ @manifest.passenger_configure_gem_path
+ @manifest.passenger_gem
+
+ @manifest.should have_package('passenger').version('2.2.2')
+ end
+
+ it "installs passenger apache module" do
+ @manifest.passenger_configure_gem_path
+ @manifest.passenger_apache_module
+
+ @manifest.should have_package('apache2-threaded-dev')
+ @manifest.should have_file('/etc/apache2/mods-available/passenger.load')
+ @manifest.should have_file('/etc/apache2/mods-available/passenger.conf').with_content(
+ /PassengerUseGlobalQueue On/
+ )
+ @manifest.should exec_command('/usr/sbin/a2enmod passenger')
+ @manifest.should exec_command('/usr/bin/ruby -S rake clean apache2')
+ end
+
+ it "allows setting booleans configurations to false" do
+ @manifest.configure(:passenger => { :use_global_queue => false })
+ @manifest.passenger_configure_gem_path
+ @manifest.passenger_apache_module
+
+ @manifest.should have_file('/etc/apache2/mods-available/passenger.conf').with_content(
+ /PassengerUseGlobalQueue Off/
+ )
+ end
+
+
+ describe "passenger_site" do
+ it "enables passenger vhost, disables default vhost, and configures mod_rewrite" do
+ @manifest.passenger_configure_gem_path
+ @manifest.passenger_site
+
+ vhost_conf_path = "/etc/apache2/sites-available/#{@manifest.configuration[:application]}"
+ @manifest.should have_file(vhost_conf_path).with_content(
+ /RailsAllowModRewrite On/
+ )
+
+ @manifest.should exec_command('/usr/sbin/a2dissite 000-default')
+ @manifest.should exec_command("/usr/sbin/a2ensite #{@manifest.configuration[:application]}")
+ end
+
+ it "supports configuring RailsBaseURI" do
+ @manifest.passenger_configure_gem_path
+ @manifest.configure(:passenger => { :rails_base_uri => '/test' })
+
+ @manifest.passenger_site
+
+ vhost_conf_path = "/etc/apache2/sites-available/#{@manifest.configuration[:application]}"
+ @manifest.should have_file(vhost_conf_path).with_content(
+ /RailsBaseURI \/test/
+ )
+ end
+
+ it "supports configuring ssl" do
+ @manifest.passenger_configure_gem_path
+ @manifest.configure(:ssl => {
+ :certificate_file => 'cert_file',
+ :certificate_key_file => 'cert_key_file',
+ :certificate_chain_file => 'cert_chain_file'
+ })
+
+ @manifest.passenger_site
+
+ @manifest.should have_file("/etc/apache2/sites-available/#{@manifest.configuration[:application]}").with_content(
+ /SSLEngine on/
+ )
+ @manifest.should have_file("/etc/apache2/sites-available/#{@manifest.configuration[:application]}").with_content(
+ /https/
+ )
+ end
+
+ it "supports basic auth" do
+ @manifest.passenger_configure_gem_path
+ @manifest.configure(:apache => {
+ :users => {
+ :jimbo => 'motorcycle',
+ :joebob => 'jimbo'
+ }
+ })
+
+ @manifest.passenger_site
+
+ vhost_conf_path = "/etc/apache2/sites-available/#{@manifest.configuration[:application]}"
+ @manifest.should have_file(vhost_conf_path).with_content(
+ /<Location \/ >/
+ )
+
+ @manifest.should have_file(vhost_conf_path).with_content(
+ /authuserfile #{@manifest.configuration[:deploy_to]}\/shared\/config\/htpasswd/
+ )
+
+ @manifest.should have_file(vhost_conf_path).with_content(
+ /require valid-user/
+ )
+ end
+
+ it "supports allowing access" do
+ @manifest.passenger_configure_gem_path
+ @manifest.configure(:apache => {
+ :users => {},
+ :deny => {},
+ :allow => ['192.168.1','env=safari_user']
+ })
+
+ @manifest.passenger_site
+
+ vhost = @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
+ vhost.should match(/<Location \/ >/)
+ vhost.should match(/allow from 192.168.1/)
+ vhost.should match(/allow from env=safari_user/)
+ end
+
+ it "supports denying access" do
+ @manifest.passenger_configure_gem_path
+ @manifest.configure(:apache => {
+ :users => {},
+ :allow => {},
+ :deny => ['192.168.1','env=safari_user']
+ })
+
+ @manifest.passenger_site
+
+ vhost_conf_path = "/etc/apache2/sites-available/#{@manifest.configuration[:application]}"
+ @manifest.should have_file(vhost_conf_path).with_content(
+ /<Location \/ >/
+ )
+
+ @manifest.should have_file(vhost_conf_path).with_content(
+ /deny from 192.168.1/
+ )
+ end
+ end
+
+ end
+
+ describe "apache server" do
+ it "generates htpasswd" do
+ @manifest.passenger_configure_gem_path
+ @manifest.configure(:apache => {
+ :users => {
+ :jimbo => 'motorcycle',
+ :joebob => 'jimbo'
+ }
+ })
+ @manifest.apache_server
+
+ @manifest.should exec_command('htpasswd -b /srv/foo/shared/config/htpasswd jimbo motorcycle')
+ @manifest.should exec_command('htpasswd -b /srv/foo/shared/config/htpasswd joebob jimbo')
+ @manifest.should have_file("#{@manifest.configuration[:deploy_to]}/shared/config/htpasswd")
+ end
+ end
+
+
+ it "supports postfix" do
+ @manifest.postfix
+
+ @manifest.should have_package("postfix")
+ end
+
+ it "supports ntp" do
+ @manifest.ntp
+
+ @manifest.should have_service("ntp")
+ @manifest.should have_package("ntp")
+ end
+
+ it "supports cron" do
+ @manifest.cron_packages
+
+ @manifest.should have_service("cron")
+ @manifest.should have_package("cron")
+ end
+
+ describe "#time_zone" do
+ it "sets default time zone" do
+ @manifest.time_zone
+
+ @manifest.should have_file("/etc/timezone").with_content("UTC\n")
+ @manifest.should have_file("/etc/localtime").symlinked_to('/usr/share/zoneinfo/UTC')
+ end
+
+ it "sets default timezone" do
+ @manifest.configure(:time_zone => nil)
+
+ @manifest.time_zone
+
+ @manifest.should have_file("/etc/timezone").with_content("UTC\n")
+ @manifest.should have_file("/etc/localtime").symlinked_to('/usr/share/zoneinfo/UTC')
+ end
+
+ it "sets configured time zone" do
+ @manifest.configure(:time_zone => 'America/New_York')
+
+ @manifest.time_zone
+
+ @manifest.should have_file("/etc/timezone").with_content("America/New_York\n")
+ @manifest.should have_file("/etc/localtime").symlinked_to('/usr/share/zoneinfo/America/New_York')
+ end
+ end
+
+ describe "#log_rotate" do
+ it "generates configuration files" do
+ @manifest.send(:logrotate, '/srv/theapp/shared/logs/*.log', {:options => %w(daily missingok compress delaycompress sharedscripts), :postrotate => 'touch /home/deploy/app/current/tmp/restart.txt'})
+ @manifest.send(:logrotate, '/srv/otherapp/shared/logs/*.log', {:options => %w(daily missingok nocompress delaycompress sharedscripts), :postrotate => 'touch /home/deploy/app/current/tmp/restart.txt'})
+
+ @manifest.should have_package("logrotate")
+
+ @manifest.should have_file("/etc/logrotate.d/srvtheappsharedlogslog.conf").with_content(/compress/)
+ @manifest.should have_file("/etc/logrotate.d/srvotherappsharedlogslog.conf").with_content(/nocompress/)
+ end
+
+ it "is configurable" do
+ @manifest.configure(
+ :deploy_to => '/srv/foo',
+ :rails_logrotate => {
+ :options => %w(foo bar baz),
+ :postrotate => 'do something'
+ }
+ )
+
+ @manifest.send(:rails_logrotate)
+
+ @manifest.should have_package("logrotate")
+ @manifest.should have_file("/etc/logrotate.d/srvfoosharedloglog.conf")
+
+ logrotate_conf = @manifest.files["/etc/logrotate.d/srvfoosharedloglog.conf"].content
+
+ logrotate_conf.should match(/foo/)
+ logrotate_conf.should_not match(/compress/)
+ logrotate_conf.should_not match(/restart\.txt/)
+ end
+ end
+
+ specify "#postgresql_server" do
+ @manifest.postgresql_server
+
+ @manifest.should have_service("postgresql-8.3")
+ @manifest.should have_package("postgresql-client")
+ @manifest.should have_package("postgresql-contrib")
+ @manifest.should have_file("/etc/postgresql/8.3/main/pg_hba.conf")
+ @manifest.should have_file("/etc/postgresql/8.3/main/postgresql.conf")
+ end
+
+ specify "#postgresql_gem" do
+ @manifest.postgresql_gem
+
+ @manifest.should have_package("postgres")
+ @manifest.should have_package("pg")
+ @manifest.should have_package("postgresql-client")
+ @manifest.should have_package("postgresql-contrib")
+ @manifest.should have_package("libpq-dev")
+ end
+
+ specify "#postgresql_database and #postgresql_user" do
+ @manifest.should_receive(:database_environment).at_least(:once).and_return({
+ :username => 'pg_username',
+ :database => 'pg_database',
+ :password => 'pg_password'
+ })
+
+ @manifest.postgresql_user
+ @manifest.postgresql_database
+
+ @manifest.should exec_command('/usr/bin/psql -c "CREATE USER pg_username WITH PASSWORD \'pg_password\'"')
+ @manifest.should exec_command('/usr/bin/createdb -O pg_username pg_database')
+ end
+
+end
View
190 spec/moonshine/manifest_spec.rb
@@ -0,0 +1,190 @@
+require 'spec_helper'
+
+module Moonshine::Iptables
+end
+
+describe Moonshine::Manifest do
+
+ after do
+ if @manifest && application_template && application_template.exist?
+ application_template.delete
+ end
+ end
+
+ def application_template
+ @application_template ||= @manifest.rails_root.join('app', 'manifests', 'templates', 'passenger.conf.erb')
+ end
+
+ it 'should load configuration' do
+ Moonshine::Manifest.configuration.should_not == nil
+ Moonshine::Manifest.configuration[:application].should_not == nil
+ end
+
+ it 'should load environment specific configuration' do
+ Moonshine::Manifest.configuration[:test_yaml].should == 'what what what'
+ end
+
+ context 'templates' do
+ it 'should use moonshine templates by default' do
+ @manifest = Moonshine::Manifest::Rails.new
+ @manifest.configure(:application => 'bar')
+
+ moonshine_template = Pathname.new(__FILE__).dirname.join('..', '..', 'lib', 'moonshine', 'manifest', 'rails', 'templates', 'passenger.vhost.erb')
+ template_contents = 'moonshine template: <%= configuration[:application] %>'
+ @manifest.stub!(:local_template).and_return(application_template)
+
+ @manifest.template(moonshine_template).should match('ServerName yourapp.com')
+ end
+
+
+ it 'should allow overriding by user provided templates in app/manifests/templates' do
+ @manifest = Moonshine::Manifest.new
+ @manifest.configure(:application => 'bar')
+
+ FileUtils.mkdir_p application_template.dirname
+ application_template.open('w') {|f| f.write "application template: <%= configuration[:application] %>" }
+
+ moonshine_template = Pathname.new(__FILE__).dirname.join('..', '..', 'lib', 'moonshine', 'manifest', 'rails', 'templates', 'passenger.conf.erb')
+ application_template = @manifest.rails_root.join('app', 'manifests', 'templates', 'passenger.conf.erb')
+ application_template.should exist
+ moonshine_template.should exist
+
+ # should return the output from that existing thing
+ @manifest.template(moonshine_template).should match('application template: bar')
+ end
+ end
+
+ it 'should load plugins' do
+ @manifest = Moonshine::Manifest.new
+ Moonshine::Manifest.plugin(:iptables).should be
+ # eval is configured in test/rails_root/vendor/plugins/moonshine_eval_test/moonshine/init.rb
+ Moonshine::Manifest.configuration[:eval].should be
+ @manifest = Moonshine::Manifest.new
+ @manifest.should respond_to(:foo)
+ @manifest.class.recipes.map(&:first).should include(:foo)
+ end
+
+ it 'should load database.yml into configuration[:database]' do
+ Moonshine::Manifest.configuration[:database].should_not == nil
+ Moonshine::Manifest.configuration[:database][:production].should == 'production'
+ end
+
+ describe '#on_stage' do
+ before { @manifest = Moonshine::Manifest.new }
+ context 'using a string' do
+ it 'should run on_stage block when stage matches the given string' do
+ @manifest.should_receive(:deploy_stage).and_return("my_stage")
+
+ @manifest.on_stage("my_stage") { "on my_stage" }.should == 'on my_stage'
+ end
+
+ it "should not call block when it doesn't match" do
+ @manifest.stub!(:deploy_stage).and_return("not_my_stage")
+
+ @manifest.on_stage("my_stage") { "on my_stage" }.should == nil
+ end
+ end
+
+ context 'using a symbol' do
+ it 'should call block when it matches' do
+ @manifest.should_receive(:deploy_stage).and_return("my_stage")
+
+ @manifest.on_stage(:my_stage) { "on my_stage" }.should == 'on my_stage'
+ end
+
+ it "should not cal block when it doesn't match" do
+ @manifest.stub!(:deploy_stage).and_return("not_my_stage")
+
+ @manifest.on_stage(:my_stage) { "on my_stage" }.should == nil
+ end
+ end
+
+ context 'using an array of strings' do
+ it 'should call block when it matches ' do
+ @manifest.stub!(:deploy_stage).and_return("my_stage")
+ @manifest.on_stage("my_stage", "my_other_stage") { "on one of my stages" }.should == 'on one of my stages'
+
+ @manifest.should_receive(:deploy_stage).and_return("my_other_stage")
+ @manifest.on_stage("my_stage", "my_other_stage") { "on one of my stages" }.should == 'on one of my stages'
+ end
+
+ it "should not call block when it doesn't match" do
+ @manifest.stub!(:deploy_stage).and_return("not_my_stage")
+
+ @manifest.on_stage("my_stage", "my_other_stage") { "on one of my stages" }.should == nil
+ end
+ end
+
+ context 'using an array of symbols' do
+ it 'should call the block it matches' do
+ @manifest.stub!(:deploy_stage).and_return("my_stage")
+
+ @manifest.on_stage(:my_stage, :my_other_stage) { "on one of my stages" }.should == 'on one of my stages'
+
+ @manifest.should_receive(:deploy_stage).and_return("my_other_stage")
+ @manifest.on_stage(:my_stage, :my_other_stage) { "on one of my stages" }.should == 'on one of my stages'
+ end
+
+ it "should not the call block when it doesn't match" do
+ @manifest.stub!(:deploy_stage).and_return("not_my_stage")
+
+ @manifest.on_stage(:my_stage, :my_other_stage) { "on one of my stages" }.should == nil
+ end
+ end
+
+ context 'using :unless with a string' do
+ it 'should not call block when it matches' do
+ @manifest.stub!(:deploy_stage).and_return("my_stage")
+
+ @manifest.on_stage(:unless => "my_stage") { "not on one of my stages" }.should == nil
+ end
+
+ it 'should call block when it does not match' do
+ @manifest.stub!(:deploy_stage).and_return("my_stage")
+
+ @manifest.on_stage(:unless => "not_my_stage") { "not on one of my stages" }.should == 'not on one of my stages'
+ end
+ end
+
+ context 'using :unless with a symbol' do
+ it 'should not call block when it matches' do
+ @manifest.stub!(:deploy_stage).and_return("my_stage")
+
+ @manifest.on_stage(:unless => :my_stage) { "not on one of my stages" }.should == nil
+ end
+
+ it 'should call block when it does not match' do
+ @manifest.stub!(:deploy_stage).and_return("my_stage")
+
+ @manifest.on_stage(:unless => :not_my_stage) { "not on one of my stages" }.should == 'not on one of my stages'
+ end
+
+ end
+
+ context 'using :unless with an array of strings' do
+ it 'should not call block when it matches' do
+ @manifest.stub!(:deploy_stage).and_return("my_stage")
+ @manifest.on_stage(:unless => ["my_stage", "my_other_stage"]) { "not on one of my stages" }.should == nil
+ end
+
+ it 'should call block when it does not match' do
+ @manifest.stub!(:deploy_stage).and_return("not_my_stage")
+ @manifest.on_stage(:unless => ["my_stage", "my_other_stage"]) { "not on one of my stages" }.should == 'not on one of my stages'
+ end
+ end
+
+ context 'using :unless with an array of symbols' do
+ it 'should not call block when it matches' do
+ @manifest.stub!(:deploy_stage).and_return("my_stage")
+ @manifest.on_stage(:unless => [:my_stage, :my_other_stage]) { "not on one of my stages" }.should == nil
+ end
+
+ it 'should call block when it does not match' do
+ @manifest.stub!(:deploy_stage).and_return("not_my_stage")
+ @manifest.on_stage(:unless => [:my_stage, :my_other_stage]) { "not on one of my stages" }.should == "not on one of my stages"
+ end
+ end
+
+ end
+
+end
View
101 spec/moonshine_generator_spec.rb
@@ -0,0 +1,101 @@
+require 'spec_helper'
+
+describe MoonshineGenerator do
+ if Rails::VERSION::MAJOR < 3
+ require 'yaml'
+
+ before do
+ FileUtils.mkdir_p(generator_rails_root)
+
+ Rails::Generator::Scripts::Generate.new.run(["moonshine"], :destination => generator_rails_root)
+ end
+
+ after do
+ FileUtils.rm_r(generator_rails_root)
+ end
+
+ it "generates correct files" do
+ capfile_path.should exist
+ manifest_path.should exist
+ templates_path.should exist
+ config_path.should exist
+ gems_path.should exist
+ deploy_path.should exist
+ end
+
+ it "generates valid config" do
+ configuration.should be_kind_of(Hash)
+ end
+
+ it "generates ApplicationManifest as a subclass of Moonshine::Manifest::Rails" do
+ manifest_path.read.should match(/class ApplicationManifest < Moonshine::Manifest::Rails/)
+ end
+
+ it "generates gem dependencies" do
+ YAML.load_file(gems_path).first.should_not == nil
+ end
+
+ it "configures application as rails_root's basename" do
+ configuration[:application].should == File.basename(RAILS_ROOT)
+ end
+
+ it "configures user as 'rails'" do
+ configuration[:user].should == 'rails'
+ end
+
+ it "configures ree as the ruby vm" do
+ configuration[:ruby].should == 'ree'
+ end
+
+ it "configures a default value for domain" do
+ configuration[:domain].should == 'yourapp.com'
+ end
+
+ it "creates a simple config/deploy.rb" do
+ deploy_path.read.should == "server 'yourapp.com', :app, :web, :db, :primary => true\n"
+ end
+
+ it "configures deploy_to to be under /srv under application" do
+ configuration[:deploy_to].should == "/srv/#{configuration[:application]}"
+ end
+
+ it "detects repository from `git config remote.origin.url`" do
+ configuration[:repository].should == `git config remote.origin.url`.chomp
+ end
+
+ private
+
+ def configuration
+ YAML.load_file(config_path)
+ end
+
+ def manifest_path
+ generator_rails_root + 'app/manifests/application_manifest.rb'
+ end
+
+ def gems_path
+ generator_rails_root + 'config/gems.yml'
+ end
+
+ def config_path
+ generator_rails_root + 'config/moonshine.yml'
+ end
+
+ def templates_path
+ generator_rails_root + 'app/manifests/templates'
+ end
+
+ def capfile_path
+ generator_rails_root + 'Capfile'
+ end
+
+ def deploy_path
+ generator_rails_root + 'config' + 'deploy.rb'
+ end
+
+ def file_list
+ Dir.glob("#{generator_rails_root}/*")
+ end
+
+ end
+end
View
29 test/test_moonshine_plugin_generator.rb → spec/moonshine_plugin_generator_spec.rb
@@ -1,29 +1,30 @@
-require 'test_helper'
-class MoonshinePluginGeneratorTest < Test::Unit::TestCase
+require 'spec_helper'
- def setup
+describe MoonshinePluginGenerator do
+
+ before do
FileUtils.mkdir_p(generator_rails_root)
Rails::Generator::Scripts::Generate.new.run(["moonshine_plugin","iptables"], :destination => generator_rails_root)
end
- def teardown
+ after do
FileUtils.rm_r(generator_rails_root)
end
- def test_generates_correct_files
- assert readme_path.exist?
- assert init_path.exist?
- assert module_path.exist?
- assert spec_path.exist?
+ it "generates correct files" do
+ readme_path.should exist
+ init_path.should exist
+ module_path.should exist
+ spec_path.should exist
end
- def test_generates_plugin_module
- assert_match /module Iptables/, module_path.read
+ it "generates a plugin module" do
+ module_path.read.should match(/module Iptables/)
end
- def test_includes_plugin_module
- assert_match /require ".*iptables\.rb"/, init_path.read
- assert_match /include Iptables/, init_path.read
+ it "generates an init.rb that includes the plugin module" do
+ init_path.read.should match(/require ".*iptables\.rb"/)
+ init_path.read.should match(/include Iptables/)
end
private
View
11 spec/pathname_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Pathname do
+ it "can match against regular expressions" do
+ Pathname.new('/etc').should =~ /#{File::SEPARATOR}/
+ end
+
+ it "can gsub" do
+ Pathname.new('/etc').gsub('etc', 'tmp').should == '/tmp'
+ end
+end
View
0  test/rails_root/config/database.yml → spec/rails_root/config/database.yml
File renamed without changes
View
0  test/rails_root/config/moonshine.yml → spec/rails_root/config/moonshine.yml
File renamed without changes
View
0  test/rails_root/config/moonshine/test.yml → spec/rails_root/config/moonshine/test.yml
File renamed without changes
View
0  ...dor/plugins/moonshine_eval_test/moonshine/init.rb → ...dor/plugins/moonshine_eval_test/moonshine/init.rb
File renamed without changes
View
27 test/test_rails_setup.rb → spec/rails_setup_spec.rb
@@ -1,8 +1,7 @@
-require 'test_helper'
+require 'spec_helper'
-class MoonshineSetupManifestTest < Test::Unit::TestCase
-
- def setup
+describe "MoonshineSetupManifest" do
+ before do
config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'generators', 'moonshine', 'templates', 'moonshine.yml'))
@user = 'user_from_capistrano'
@application = 'app_from_capistrano'
@@ -15,17 +14,21 @@ def setup
@manifest = MoonshineSetupManifest.new
end
- def teardown
+ after do
FileUtils.rm_r("/tmp/moonshine.yml") rescue true
end
- def test_creates_directories
- assert @manifest.class.recipes.map(&:first).include?(:directories)
+ it "creates deploy_to directory" do
+ @manifest.should use_recipe(:directories)
+
@manifest.directories
- assert_not_nil deploy_to = @manifest.files["#{@manifest.configuration[:deploy_to]}"]
- assert_equal :directory, deploy_to.ensure
- assert_equal @user, deploy_to.owner
- assert_equal @user, deploy_to.group
+
+ deploy_to = @manifest.files["#{@manifest.configuration[:deploy_to]}"]
+
+ deploy_to.should_not == nil
+ deploy_to.ensure.should == :directory
+ deploy_to.owner.should == @user
+ deploy_to.group.should == @user
end
-end
+end
View
2  spec/spec.opts
@@ -0,0 +1,2 @@
+--colour
+--format progress
View
18 spec/spec_helper.rb
@@ -0,0 +1,18 @@
+require 'fileutils'
+require 'rubygems'
+require 'spec/autorun'
+
+require 'ginger'
+
+# Requires supporting files with custom matchers and macros, etc,
+# in ./support/ and its subdirectories.
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+
+require 'moonshine'
+require 'shadow_puppet/test'
+
+Spec::Runner.configure do |config|
+ config.include MoonshineHelpers
+ config.extend MoonshineHelpers::ClassMethods
+end
+
View
31 spec/support/moonshine_helpers.rb
@@ -0,0 +1,31 @@
+require 'pathname'
+$here = Pathname.new(__FILE__).dirname.dirname
+
+module MoonshineHelpers
+ def fake_rails_root
+ self.class.fake_rails_root
+ end
+
+ def generator_rails_root
+ self.class.generator_rails_root
+ end
+
+ def in_apache_if_module(contents, some_module)
+ contents.should =~ /<IfModule #{some_module}>(.*)<\/IfModule>/m
+
+ contents.match(/<IfModule #{some_module}>(.*)<\/IfModule>/m)
+ yield $1 if block_given?
+ end
+
+ module ClassMethods
+ def fake_rails_root
+ $here.join('rails_root')
+ end
+
+
+ def generator_rails_root
+ $here.join('generator_rails_root')
+ end
+ end
+
+end
View
136 spec/support/moonshine_matchers.rb
@@ -0,0 +1,136 @@
+Spec::Matchers.define :have_apache_directive do |directive, value|
+ match do |actual|
+ if actual.respond_to?(:content)
+ actual = actual.content
+ end
+
+ if actual =~ /^\s*#{directive}\s+(\w+)[^#\n]*/
+ @found_value = $1
+ value.to_s == @found_value
+ else
+ false
+ end
+ end
+
+ failure_message_for_should do |actual|
+ if @found_value
+ "expected to <#{value}> for <#{directive}>, but got #{@found_value}"
+ else
+ "expected to find a value for <#{directive}>"
+ end
+ end
+
+ description do
+ "should have Apache #{directive} with value of #{value}"
+ end
+end
+
+Spec::Matchers.define :use_recipe do |expected|
+ match do |manifest|
+ recipes = manifest.recipes.map(&:first)
+ recipes.include?(expected)
+ end
+
+ description do
+ "should use #{expected} recipe"
+ end
+end
+
+Spec::Matchers.define :have_package do |expected|
+ match do |manifest|
+ package = manifest.packages[expected]
+ result = !package.nil?
+ if @version
+ result &&= package.ensure == @version
+ end
+ if @provider
+ result &&= package.provider == @provider.to_sym
+ end
+ result
+ end
+
+ def version(version)
+ @version = version
+ self
+ end
+
+ def from_provider(provider)
+ @provider = provider
+ self
+ end
+
+ failure_message_for_should do |actual|
+ "expected manifest to have package #{expected}, but did not"
+ end
+
+ failure_message_for_should_not do |actual|
+ "expected manifest to not have package #{expected}, but did"
+ end
+
+end
+
+Spec::Matchers.define :have_service do |expected|
+ match do |manifest|
+ !manifest.services[expected].nil?
+ end
+
+ failure_message_for_should do |actual|
+ "expected manifest to have #{expected}, but did not"
+ end
+
+ failure_message_for_should_not do |actual|
+ "expected manifest to not have #{expected}, but did"
+ end
+end
+
+Spec::Matchers.define :have_file do |expected|
+ match do |manifest|
+ @file = manifest.files[expected]
+ result = !@file.nil?
+ if @str_or_regex
+ @str_or_regex_matched = @file.content.match(@str_or_regex)
+ result &&= @file.content && @str_or_regex_matched
+ elsif @symlink_target
+ @symlinked_to_target = @file.ensure == @symlink_target
+ result &&= @symlinked_to_target
+ end
+ result
+ end
+
+ def with_content(str_or_regex)
+ @str_or_regex = str_or_regex
+ self
+ end
+
+ def symlinked_to(file)
+ @symlink_target = file
+ self
+ end
+
+ failure_message_for_should do |actual|
+ if @str_or_regex
+ if !@str_or_regex_matched
+ "expected to #{expected} to match #{@str_or_regex.inspect}, but it did not match. Contains:\n#{@file.content}"
+ else
+ "expected to #{expected} to match #{@str_or_regex.inspect}, but it didn't exist"
+ end
+ elsif @symlink_target
+ if !@symlinked_to_target
+ "expected to #{expected} to be symlinked to #{@symlink_target}, but was not"
+ else
+ "expected to #{expected} to be symlinked to #{@symlink_target}, but it didn't exist"
+ end
+ else
+ "expected to #{expected} to match #{@str_or_regex.inspect}, but it didn't exist"
+ end
+ end
+end
+
+Spec::Matchers.define :exec_command do |command|
+ match do |manifest|
+ manifest.execs.find do |name, exec|
+ exec.command == command
+ end
+ end
+
+end
View
20 spec/support/rails_2_generator_kludge.rb
@@ -0,0 +1,20 @@
+# rails version specific kludge to get generator tests working
+require 'rails/version'
+if Rails::VERSION::MAJOR == 2
+ require 'logger'
+ RAILS_ROOT = $here.join('rails_root').to_s
+ RAILS_DEFAULT_LOGGER = Logger.new($here.join('test.log')) # avoids generator output on stdout
+
+ ENV['RAILS_ENV'] = 'test'
+ ENV['RAILS_ROOT'] = fake_rails_root = $here.join('rails_root')
+ FileUtils.mkdir_p RAILS_ROOT
+
+
+ require 'initializer'
+ Rails.configuration = Rails::Configuration.new
+
+ require 'rails_generator'
+ require 'rails_generator/scripts/generate'
+ Rails::Generator::Base.sources << Rails::Generator::PathSource.new(:moonshine, $here.join('..', 'generators'))
+ Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(File.new($here.join('generator.log').to_s, 'w'))
+end
View
117 test/moonshine/manifest/test_apache.rb
@@ -1,117 +0,0 @@
-require 'test_helper'
-
-class Moonshine::Manifest::ApacheTest < Test::Unit::TestCase
- def setup
- @manifest = Moonshine::Manifest::Rails.new
- end
-
- def test_default_configuration
- @manifest.apache_server
-
- apache2_conf_content = @manifest.files['/etc/apache2/apache2.conf'].content
-
- assert_kind_of Hash, @manifest.configuration[:apache]
-
- assert_equal 'Off', @manifest.configuration[:apache][:keep_alive]
- assert_apache_directive apache2_conf_content, 'KeepAlive', 'Off'
-
- assert_equal 100, @manifest.configuration[:apache][:max_keep_alive_requests]
- assert_apache_directive apache2_conf_content, 'MaxKeepAliveRequests', 100
-
- assert_equal 15, @manifest.configuration[:apache][:keep_alive_timeout]
- assert_apache_directive apache2_conf_content, 'KeepAliveTimeout', 15
-
- assert_equal 150, @manifest.configuration[:apache][:max_clients]
- assert_apache_directive apache2_conf_content, 'MaxClients', 150
-
- assert_equal 16, @manifest.configuration[:apache][:server_limit]
- assert_apache_directive apache2_conf_content, 'ServerLimit', 16
-
- assert_equal 300, @manifest.configuration[:apache][:timeout]
- assert_apache_directive apache2_conf_content, 'Timeout', 300
- end
-
- def test_overridden_configuration_early
- @manifest.configure :apache => {
- :keep_alive => 'On',
- :max_keep_alive_requests => 200,
- :keep_alive_timeout => 30,
- :max_clients => 300,
- :server_limit => 32,
- :timeout => 600
- }
- @manifest.apache_server
-
- apache2_conf_content = @manifest.files['/etc/apache2/apache2.conf'].content
-
- assert_equal 600, @manifest.configuration[:apache][:timeout]
- assert_apache_directive apache2_conf_content, 'Timeout', 600
-
- assert_equal 'On', @manifest.configuration[:apache][:keep_alive]
- assert_apache_directive apache2_conf_content, 'KeepAlive', 'On'
-
- assert_equal 200, @manifest.configuration[:apache][:max_keep_alive_requests]
- assert_apache_directive apache2_conf_content, 'MaxKeepAliveRequests', 200
-
- assert_equal 30, @manifest.configuration[:apache][:keep_alive_timeout]
- assert_apache_directive apache2_conf_content, 'KeepAliveTimeout', 30
-
- in_apache_if_module apache2_conf_content, 'mpm_worker_module' do |mpm_worker_module|
- assert_equal 300, @manifest.configuration[:apache][:max_clients]
- assert_apache_directive mpm_worker_module, 'MaxClients', 300
-
- assert_equal 32, @manifest.configuration[:apache][:server_limit]
- assert_apache_directive mpm_worker_module, 'ServerLimit', 32
- end
-
- end
-
- def test_overridden_configuration_late
- @manifest.apache_server
- @manifest.configure :apache => { :keep_alive => 'On' }
-
- apache2_conf_content = @manifest.files['/etc/apache2/apache2.conf'].content
-
- assert_equal 'On', @manifest.configuration[:apache][:keep_alive]
- assert_apache_directive apache2_conf_content, 'KeepAlive', 'On'
- end
-
- def test_default_keepalive_off
- @manifest.apache_server
-
- apache2_conf_content = @manifest.files['/etc/apache2/apache2.conf'].content
- assert_apache_directive apache2_conf_content, 'KeepAlive', 'Off'
- end
-
- def test_installs_apache
- @manifest.apache_server
-
- assert_not_nil apache = @manifest.services["apache2"]
- assert_equal @manifest.package('apache2-mpm-worker').to_s, apache.require.to_s
- end
-
- def test_enables_mod_ssl_if_ssl
- @manifest.configure(:ssl => {
- :certificate_file => 'cert_file',
- :certificate_key_file => 'cert_key_file',
- :certificate_chain_file => 'cert_chain_file'
- })
-
- @manifest.apache_server
-
- assert_not_nil @manifest.execs.find { |n, r| r.command == '/usr/sbin/a2enmod ssl' }
- end
-
- def test_enables_mod_rewrite
- @manifest.apache_server
-
- assert_not_nil apache = @manifest.execs["a2enmod rewrite"]
- end
-
- def test_enables_mod_status
- @manifest.apache_server
-
- assert_not_nil apache = @manifest.execs["a2enmod status"]
- assert_match /127.0.0.1/, @manifest.files["/etc/apache2/mods-available/status.conf"].content
- end
-end
View
369 test/moonshine/manifest/test_rails.rb
@@ -1,369 +0,0 @@
-require 'test_helper'
-
-# mock out the gem source index to fake like passenger is installed, but
-# nothing else
-module Gem #:nodoc:
- class SourceIndex #:nodoc:
- alias_method :orig_search, :search
- def search(gem_pattern, platform_only = false)
- if gem_pattern.name.to_s =~ /passenger/
- orig_search(gem_pattern, platform_only)
- else
- []
- end
- end
- end
-end
-
-class Moonshine::Manifest::RailsTest < Test::Unit::TestCase
-
- def setup
- @manifest = Moonshine::Manifest::Rails.new
- end
-
- def test_default_stack
- @manifest.expects(:database_environment).at_least_once.returns({:adapter => 'mysql'})
-
- @manifest.default_stack
-
- assert @manifest.recipes.map(&:first).include?(:apache_server), 'apache_server'
- [:passenger_gem, :passenger_configure_gem_path, :passenger_apache_module, :passenger_site].each do |passenger_stack|
- assert @manifest.recipes.map(&:first).include?(passenger_stack), passenger_stack.to_s
- end
-
- [:mysql_server, :mysql_gem, :mysql_database, :mysql_user, :mysql_fixup_debian_start].each do |mysql_stack|
- assert @manifest.recipes.map(&:first).include?(mysql_stack), mysql_stack.to_s
- end
- [:rails_rake_environment, :rails_gems, :rails_directories, :rails_bootstrap, :rails_migrations, :rails_logrotate].each do |rails_stack|
- assert @manifest.recipes.map(&:first).include?(rails_stack), rails_stack.to_s
- end
-
- [:ntp, :time_zone, :postfix, :cron_packages, :motd, :security_updates].each do |os_stack|
- assert @manifest.recipes.map(&:first).include?(os_stack), os_stack.to_s
- end
- end
-
- def test_default_stack_with_postgresql
- @manifest.expects(:database_environment).at_least_once.returns({:adapter => 'postgresql' })
-
- @manifest.default_stack
-
- [:postgresql_server, :postgresql_gem, :postgresql_user, :postgresql_database].each do |pgsql_stack|
- assert @manifest.recipes.map(&:first).include?(pgsql_stack), pgsql_stack.to_s
- end
- end
-
- def test_default_stack_with_sqlite
- @manifest.expects(:database_environment).at_least_once.returns({:adapter => 'sqlite' })
-
- @manifest.default_stack
-
- assert @manifest.recipes.map(&:first).include?(:sqlite3), 'sqlite3'
- end
-
- def test_automatic_security_updates
- @manifest.configure(:unattended_upgrade => { :package_blacklist => ['foo', 'bar', 'widget']})
- @manifest.configure(:user => 'rails')
-
- @manifest.security_updates
-
- assert_not_nil @manifest.packages["unattended-upgrades"]
- assert_not_nil @manifest.files["/etc/apt/apt.conf.d/10periodic"]
- assert_not_nil @manifest.files["/etc/apt/apt.conf.d/50unattended-upgrades"]
- assert_match /APT::Periodic::Unattended-Upgrade "1"/, @manifest.files["/etc/apt/apt.conf.d/10periodic"].params[:content].value
- assert_match /Unattended-Upgrade::Mail "rails@localhost";/, @manifest.files["/etc/apt/apt.conf.d/50unattended-upgrades"].params[:content].value
- assert_match /"foo";/, @manifest.files["/etc/apt/apt.conf.d/50unattended-upgrades"].params[:content].value
- end
-
- def test_is_executable
- assert @manifest.executable?
- end
-
- def test_sets_up_gem_sources
- @manifest.rails_gems
- assert_match /gems.github.com/, @manifest.files["/etc/gemrc"].content
- end
-
- def test_loads_gems_from_config_hash
- @manifest.configure(:gems => [ { :name => 'jnewland-pulse', :source => 'http://gems.github.com' } ])
- @manifest.rails_gems
- assert_not_nil Moonshine::Manifest::Rails.configuration[:gems]
- Moonshine::Manifest::Rails.configuration[:gems].each do |gem|
- assert_not_nil gem_resource = @manifest.packages[gem[:name]]
- assert_equal :gem, gem_resource.provider
- end
- assert_nil @manifest.packages['jnewland-pulse'].source
- end
-
- def test_magically_loads_gem_dependencies
- @manifest.configure(:gems => [
- { :name => 'webrat' },
- { :name => 'thoughtbot-paperclip', :source => 'http://gems.github.com' }
- ])
- @manifest.rails_gems
- assert_not_nil @manifest.packages['webrat']
- assert_not_nil @manifest.packages['thoughtbot-paperclip']
- assert_not_nil @manifest.packages['libxml2-dev']
- assert_not_nil @manifest.packages['imagemagick']
- end
-
- def test_creates_directories
- config = {
- :application => 'foo',
- :user => 'foo',
- :deploy_to => '/srv/foo'
- }
- @manifest.configure(config)
-
- @manifest.rails_directories
-
- assert_not_nil shared_dir = @manifest.files["/srv/foo/shared"]
- assert_equal :directory, shared_dir.ensure
- assert_equal 'foo', shared_dir.owner
- assert_equal 'foo', shared_dir.group
- end
-
- def test_installs_passenger_gem
- @manifest.configure(:passenger => { :version => nil })
-
- @manifest.passenger_configure_gem_path
- @manifest.passenger_gem
-
- assert_not_nil @manifest.packages["passenger"]
- assert_equal :latest, @manifest.packages["passenger"].ensure
- end
-
- def test_can_pin_passenger_to_a_specific_version
- @manifest.configure(:passenger => { :version => '2.2.2' })
- @manifest.passenger_configure_gem_path
- @manifest.passenger_gem
- assert_not_nil @manifest.packages["passenger"]
- assert_equal '2.2.2', @manifest.packages["passenger"].ensure
- end
-
- def test_installs_passenger_module
- @manifest.passenger_configure_gem_path
- @manifest.passenger_apache_module
-
- assert_not_nil @manifest.packages['apache2-threaded-dev']
- assert_not_nil @manifest.files['/etc/apache2/mods-available/passenger.load']
- assert_not_nil @manifest.files['/etc/apache2/mods-available/passenger.conf']
- assert_match /PassengerUseGlobalQueue On/, @manifest.files['/etc/apache2/mods-available/passenger.conf'].content
- assert_not_nil @manifest.execs.find { |n, r| r.command == '/usr/sbin/a2enmod passenger' }
- assert_not_nil @manifest.execs.find { |n, r| r.command == '/usr/bin/ruby -S rake clean apache2' }
- end
-
- def test_setting_passenger_booleans_to_false
- @manifest.configure(:passenger => { :use_global_queue => false })
- @manifest.passenger_configure_gem_path
- @manifest.passenger_apache_module
- assert_match /PassengerUseGlobalQueue Off/, @manifest.files['/etc/apache2/mods-available/passenger.conf'].content
- end
-
- def test_configures_passenger_vhost
- @manifest.passenger_configure_gem_path
- @manifest.passenger_site
-
- assert_not_nil @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"]
- assert_match /RailsAllowModRewrite On/, @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
- assert_not_nil @manifest.execs.find { |n, r| r.command == '/usr/sbin/a2dissite 000-default' }
- assert_not_nil @manifest.execs.find { |n, r| r.command == "/usr/sbin/a2ensite #{@manifest.configuration[:application]}" }
- end
-
- def test_passenger_vhost_configuration
- @manifest.passenger_configure_gem_path
- @manifest.configure(:passenger => { :rails_base_uri => '/test' })
-
- @manifest.passenger_site
-
- assert_match /RailsBaseURI \/test/, @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
- end
-
- def test_ssl_vhost_configuration
- @manifest.passenger_configure_gem_path
- @manifest.configure(:ssl => {
- :certificate_file => 'cert_file',
- :certificate_key_file => 'cert_key_file',
- :certificate_chain_file => 'cert_chain_file'
- })
-
- @manifest.passenger_site
-
- assert_match /SSLEngine on/, @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
- assert_match /https/, @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
- end
-
- def test_htpasswd_generation
- @manifest.passenger_configure_gem_path
- @manifest.configure(:apache => {
- :users => {
- :jimbo => 'motorcycle',
- :joebob => 'jimbo'
- }
- })
- @manifest.apache_server
-
- assert_not_nil @manifest.execs.find { |n, r| r.command == 'htpasswd -b /srv/foo/shared/config/htpasswd jimbo motorcycle' }
- assert_not_nil @manifest.execs.find { |n, r| r.command == 'htpasswd -b /srv/foo/shared/config/htpasswd joebob jimbo' }
- assert_not_nil @manifest.files["#{@manifest.configuration[:deploy_to]}/shared/config/htpasswd"]
- end
-
- def test_vhost_basic_auth_configuration
- @manifest.passenger_configure_gem_path
- @manifest.configure(:apache => {
- :users => {
- :jimbo => 'motorcycle',
- :joebob => 'jimbo'
- }
- })
-
- @manifest.passenger_site
-
- assert_match /<Location \/ >/, @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
- assert_match /authuserfile #{@manifest.configuration[:deploy_to]}\/shared\/config\/htpasswd/, @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
- assert_match /require valid-user/, @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
- end
-
- def test_vhost_allow_configuration
- @manifest.passenger_configure_gem_path
- @manifest.configure(:apache => {
- :users => {},
- :deny => {},
- :allow => ['192.168.1','env=safari_user']
- })
-
- @manifest.passenger_site
-
- vhost = @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
- assert_match /<Location \/ >/, vhost
- assert_match /allow from 192.168.1/, vhost
- assert_match /allow from env=safari_user/, vhost
- end
-
- def test_vhost_deny_configuration
- @manifest.passenger_configure_gem_path
- @manifest.configure(:apache => {
- :users => {},
- :allow => {},
- :deny => ['192.168.1','env=safari_user']
- })
-
- @manifest.passenger_site
-
- assert_match /<Location \/ >/, @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
- assert_match /deny from 192.168.1/, @manifest.files["/etc/apache2/sites-available/#{@manifest.configuration[:application]}"].content
- end
-
- def test_installs_postfix
- @manifest.postfix
-
- assert_not_nil @manifest.packages["postfix"]
- end
-
- def test_installs_ntp
- @manifest.ntp
-
- assert_not_nil @manifest.services["ntp"]
- assert_not_nil @manifest.packages["ntp"]
- end
-
- def test_installs_cron
- @manifest.cron_packages
-
- assert_not_nil @manifest.services["cron"]
- assert_not_nil @manifest.packages["cron"]
- end
-
- def test_sets_default_time_zone
- @manifest.time_zone
-
- assert_not_nil @manifest.files["/etc/timezone"]
- assert_not_nil @manifest.packages["/etc/localtime"]
- assert_equal '/usr/share/zoneinfo/UTC', @manifest.files["/etc/localtime"].ensure
- assert_equal "UTC\n", @manifest.files["/etc/timezone"].content
- end
-
- def test_sets_default_time_zone
- @manifest.configure(:time_zone => nil)
-
- @manifest.time_zone
-
- assert_not_nil @manifest.files["/etc/timezone"]
- assert_equal "UTC\n", @manifest.files["/etc/timezone"].content
- assert_not_nil @manifest.files["/etc/localtime"]
- assert_equal '/usr/share/zoneinfo/UTC', @manifest.files["/etc/localtime"].ensure
- end
-
- def test_sets_configured_time_zone
- @manifest.configure(:time_zone => 'America/New_York')
-
- @manifest.time_zone
-
- assert_not_nil @manifest.files["/etc/timezone"]
- assert_equal "America/New_York\n", @manifest.files["/etc/timezone"].content
- assert_not_nil @manifest.files["/etc/localtime"]
- assert_equal '/usr/share/zoneinfo/America/New_York', @manifest.files["/etc/localtime"].ensure
- end
-
- def test_logroate_helper_generates_config
- @manifest.send(:logrotate, '/srv/theapp/shared/logs/*.log', {:options => %w(daily missingok compress delaycompress sharedscripts), :postrotate => 'touch /home/deploy/app/current/tmp/restart.txt'})
- @manifest.send(:logrotate, '/srv/otherapp/shared/logs/*.log', {:options => %w(daily missingok nocompress delaycompress sharedscripts), :postrotate => 'touch /home/deploy/app/current/tmp/restart.txt'})
-
- assert_not_nil @manifest.packages["logrotate"]
- assert_match /compress/, @manifest.files["/etc/logrotate.d/srvtheappsharedlogslog.conf"].content
- assert_match /nocompress/, @manifest.files["/etc/logrotate.d/srvotherappsharedlogslog.conf"].content
- end
-
- def test_rails_logroate_is_configurable
- @manifest.configure(
- :deploy_to => '/srv/foo',
- :rails_logrotate => {
- :options => %w(foo bar baz),
- :postrotate => 'do something'
- }
- )
-
- @manifest.send(:rails_logrotate)
-
- assert_not_nil @manifest.packages["logrotate"]
- assert_match /foo/, @manifest.files["/etc/logrotate.d/srvfoosharedloglog.conf"].content
- assert_no_match /compress/, @manifest.files["/etc/logrotate.d/srvfoosharedloglog.conf"].content
- assert_match /do something/, @manifest.files["/etc/logrotate.d/srvfoosharedloglog.conf"].content
- assert_no_match /restart\.txt/, @manifest.files["/etc/logrotate.d/srvfoosharedloglog.conf"].content
- end
-
- def test_postgresql_server
- @manifest.postgresql_server
-
- assert_not_nil @manifest.services["postgresql-8.3"]
- assert_not_nil @manifest.packages["postgresql-client"]
- assert_not_nil @manifest.packages["postgresql-contrib"]
- assert_not_nil @manifest.files["/etc/postgresql/8.3/main/pg_hba.conf"]
- assert_not_nil @manifest.files["/etc/postgresql/8.3/main/postgresql.conf"]
- end
-
- def test_postgresql_gem
- @manifest.postgresql_gem
-
- assert_not_nil @manifest.packages["postgres"]
- assert_not_nil @manifest.packages["pg"]
- assert_not_nil @manifest.packages["postgresql-client"]
- assert_not_nil @manifest.packages["postgresql-contrib"]
- assert_not_nil @manifest.packages["libpq-dev"]
- end
-
- def test_postgresql_database_and_user
- @manifest.expects(:database_environment).at_least_once.returns({
- :username => 'pg_username',
- :database => 'pg_database',
- :password => 'pg_password'
- })
-
- @manifest.postgresql_user
- @manifest.postgresql_database
-
- assert_not_nil @manifest.execs.find { |n, r| r.command == '/usr/bin/psql -c "CREATE USER pg_username WITH PASSWORD \'pg_password\'"' }
- assert_not_nil @manifest.execs.find { |n, r| r.command == '/usr/bin/createdb -O pg_username pg_database' }
- end
-
-end
View
182 test/moonshine/test_manifest.rb
@@ -1,182 +0,0 @@
-require 'test_helper'
-
-module Moonshine::Iptables
-end
-
-class Moonshine::ManifestTest < Test::Unit::TestCase
-
- def teardown
- if @manifest && application_template && application_template.exist?
- application_template.delete
- end
- end
-
- def test_loads_configuration
- assert_not_nil Moonshine::Manifest.configuration
- assert_not_nil Moonshine::Manifest.configuration[:application]
- end
-
- def test_loads_environment_specific_configuration
- assert_equal 'what what what', Moonshine::Manifest.configuration[:test_yaml]
- end
-
- def test_moonshine_templates
- @manifest = Moonshine::Manifest::Rails.new
- @manifest.configure(:application => 'bar')
-
- moonshine_template = Pathname.new(__FILE__).dirname.join('..', '..', 'lib', 'moonshine', 'manifest', 'rails', 'templates', 'passenger.vhost.erb')
- template_contents = 'moonshine template: <%= configuration[:application] %>'
- @manifest.stubs(:local_template).returns(application_template)
-
- assert_match 'ServerName yourapp.com', @manifest.template(moonshine_template)
- end
-
- def application_template
- @application_template ||= @manifest.rails_root.join('app', 'manifests', 'templates', 'passenger.conf.erb')
- end
-
- def test_app_templates_override_moonshine_templates
- @manifest = Moonshine::Manifest.new
- @manifest.configure(:application => 'bar')
-
- FileUtils.mkdir_p application_template.dirname
- application_template.open('w') {|f| f.write "application template: <%= configuration[:application] %>" }
-
- moonshine_template = Pathname.new(__FILE__).dirname.join('..', '..', 'lib', 'moonshine', 'manifest', 'rails', 'templates', 'passenger.conf.erb')
- application_template = @manifest.rails_root.join('app', 'manifests', 'templates', 'passenger.conf.erb')
- assert application_template.exist?, "#{application_template} should exist, but didn't"
- assert moonshine_template.exist?, "#{moonshine_template} should exist, but didn't"
-
- # should return the output from that existing thing
- assert_match 'application template: bar', @manifest.template(moonshine_template)
- end
-
- def test_loads_plugins
- @manifest = Moonshine::Manifest.new
- assert Moonshine::Manifest.plugin(:iptables)
- # eval is configured in test/rails_root/vendor/plugins/moonshine_eval_test/moonshine/init.rb
- assert Moonshine::Manifest.configuration[:eval]
- @manifest = Moonshine::Manifest.new
- assert @manifest.respond_to?(:foo)
- assert @manifest.class.recipes.map(&:first).include?(:foo)
- end
-
- def test_loads_database_config
- assert_not_equal nil, Moonshine::Manifest.configuration[:database]
- assert_equal 'production', Moonshine::Manifest.configuration[:database][:production]
- end
-
- def test_on_stage_runs_when_string_stage_matches
- @manifest = Moonshine::Manifest.new
- @manifest.expects(:deploy_stage).returns("my_stage")
-
- assert_equal 'on my_stage', @manifest.on_stage("my_stage") { "on my_stage" }
- end
-
- def test_on_stage_runs_when_symbol_stage_matches
- @manifest = Moonshine::Manifest.new
- @manifest.expects(:deploy_stage).returns("my_stage")
-
- assert_equal 'on my_stage', @manifest.on_stage(:my_stage) { "on my_stage" }
- end
-
- def test_on_stage_does_not_run_when_string_stage_does_not_match
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("not_my_stage")
-
- assert_nil @manifest.on_stage("my_stage") { "on my_stage" }
- end
-
- def test_on_stage_does_not_run_when_symbol_stage_does_not_match
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("not_my_stage")
-
- assert_nil @manifest.on_stage(:my_stage) { "on my_stage" }
- end
-
- def test_on_stage_runs_when_stage_included_in_string_array
- @manifest = Moonshine::Manifest.new
-
- @manifest.stubs(:deploy_stage).returns("my_stage")
- assert_equal 'on one of my stages', @manifest.on_stage("my_stage", "my_other_stage") { "on one of my stages" }
-
- @manifest.expects(:deploy_stage).returns("my_other_stage")
- assert_equal 'on one of my stages', @manifest.on_stage("my_stage", "my_other_stage") { "on one of my stages" }
- end
-
- def test_on_stage_runs_when_stage_included_in_symbol_array
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("my_stage")
-
- assert_equal 'on one of my stages', @manifest.on_stage(:my_stage, :my_other_stage) { "on one of my stages" }
-
- @manifest.expects(:deploy_stage).returns("my_other_stage")
- assert_equal 'on one of my stages', @manifest.on_stage(:my_stage, :my_other_stage) { "on one of my stages" }
- end
-
- def test_on_stage_does_not_run_when_stage_not_in_string_array
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("not_my_stage")
-
- assert_nil @manifest.on_stage("my_stage", "my_other_stage") { "on one of my stages" }
- end
-
- def test_on_stage_does_not_run_when_stage_not_in_symbol_array
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("not_my_stage")
-
- assert_nil @manifest.on_stage(:my_stage, :my_other_stage) { "on one of my stages" }
- end
-
- def test_on_stage_unless_does_not_run_when_string_stage_matches
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("my_stage")
-
- assert_nil @manifest.on_stage(:unless => "my_stage") { "not on one of my stages" }
- end
-
- def test_on_stage_unless_does_not_run_when_symbol_stage_matches
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("my_stage")
-
- assert_nil @manifest.on_stage(:unless => :my_stage) { "not on one of my stages" }
- end
-
- def test_on_stage_unless_runs_when_string_stage_does_not_match
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("my_stage")
-
- assert_equal 'not on one of my stages', @manifest.on_stage(:unless => "not_my_stage") { "not on one of my stages" }
- end
-
- def test_on_stage_unless_runs_when_symbol_stage_does_not_match
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("my_stage")
-
- assert_equal 'not on one of my stages', @manifest.on_stage(:unless => :not_my_stage) { "not on one of my stages" }
- end
-
- def test_on_stage_unless_does_not_runs_when_stage_in_string_array
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("my_stage")
- assert_nil @manifest.on_stage(:unless => ["my_stage", "my_other_stage"]) { "not on one of my stages" }
- end
-
- def test_on_stage_unless_does_not_runs_when_stage_in_symbol_array
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("my_stage")
- assert_nil @manifest.on_stage(:unless => [:my_stage, :my_other_stage]) { "not on one of my stages" }
- end
-
- def test_on_stage_unless_runs_when_stage_not_in_string_array
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("not_my_stage")
- assert_equal "not on one of my stages", @manifest.on_stage(:unless => ["my_stage", "my_other_stage"]) { "not on one of my stages" }
- end
-
- def test_on_stage_unless_runs_when_stage_not_in_symbol_array
- @manifest = Moonshine::Manifest.new
- @manifest.stubs(:deploy_stage).returns("not_my_stage")
- assert_equal "not on one of my stages", @manifest.on_stage(:unless => [:my_stage, :my_other_stage]) { "not on one of my stages" }
- end
-end
View
16 test/support/rails_2_generator_kludge.rb
@@ -1,16 +0,0 @@
-require 'logger'
-RAILS_ROOT = $here.join('rails_root').to_s
-RAILS_DEFAULT_LOGGER = Logger.new($here.join('test.log')) # avoids generator output on stdout
-
-ENV['RAILS_ENV'] = 'test'
-ENV['RAILS_ROOT'] = fake_rails_root = $here.join('rails_root')
-FileUtils.mkdir_p RAILS_ROOT
-
-
-require 'initializer'
-Rails.configuration = Rails::Configuration.new
-
-require 'rails_generator'
-require 'rails_generator/scripts/generate'
-Rails::Generator::Base.sources << Rails::Generator::PathSource.new(:moonshine, $here.join('..', 'generators'))
-Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(File.new($here.join('generator.log').to_s, 'w'))
View
71 test/test_helper.rb
@@ -1,71 +0,0 @@
-require 'fileutils'
-require 'rubygems'
-require 'test/unit'
-require 'ginger'
-
-require 'pathname'
-$here = Pathname.new(__FILE__).dirname
-
-# rails version specific kludge to get generator tests working
-require 'rails/version'
-if Rails::VERSION::MAJOR == 2
- require 'support/rails_2_generator_kludge'
-end
-
-require 'moonshine'
-require 'shadow_puppet/test'
-require 'mocha'
-
-
-Test::Unit::TestCase.class_eval do
- def fake_rails_root
- self.class.fake_rails_root
- end
-
- def self.fake_rails_root
- $here.join('rails_root')
- end
-
- def generator_rails_root
- self.class.generator_rails_root
- end
-
- def self.generator_rails_root
- $here.join('generator_rails_root')
- end
-
- def assert_manifest_file_exists(manifest, path)
- message = "manifest (#{manifest.files.keys.join(', ')}) files does not contain #{path}"
- assert_block message do
- manifest.files.has_key?(path.to_s)
- end
- end
-
- def assert_apache_directive(contents, directive, value)
- # Make sure directive is there first
- assert_match directive, contents
- assert_block "Wasn't able to find a value for <#{directive}>" do
- if contents =~ /^\s*#{directive}\s+(\w+)[^#\n]*/
- assert_block "Expected <#{value}> for <#{directive}>, but got <#{$1}>" do
- $1 == value.to_s
- end
- true
- else
- false
- end
- end
- end
-
- def in_apache_if_module(contents, some_module)
- assert_block "Doesn't contain <IfModule #{some_module}>" do
- if contents =~ /<IfModule #{some_module}>(.*)<\/IfModule>/m
- yield $1 if block_given?
- true
- else
- false
- end
- end
-
- end
-
-end
View
104 test/test_moonshine_generator.rb
@@ -1,104 +0,0 @@
-require 'test_helper'
-
-class MoonshineGeneratorTest < Test::Unit::TestCase
- if Rails::VERSION::MAJOR < 3
- require 'yaml'
-
- def setup
- FileUtils.mkdir_p(generator_rails_root)
-
- @original_files = file_list
-
- Rails::Generator::Scripts::Generate.new.run(["moonshine"], :destination => generator_rails_root)
- @new_files = (file_list - @original_files)
- end
-
- def teardown
- FileUtils.rm_r(generator_rails_root)
- end
-
- def test_generates_correct_files
- assert File.exist?(capfile_path)
- assert File.exist?(manifest_path)
- assert File.exist?(templates_path)
- assert File.exist?(config_path)
- assert File.exist?(gems_path)
- assert File.exist?(deploy_path)
- end
-
- def test_generates_valid_config_file
- assert_instance_of Hash, configuration
- end
-
- def test_generates_application_manifest_class
- assert_match /class ApplicationManifest < Moonshine::Manifest::Rails/, File.read(manifest_path)
- end
-
- def test_generates_gem_dependencies
- assert_not_nil YAML.load_file(gems_path).first
- end
-
- def test_application_is_rails_root_basename
- assert_equal File.basename(RAILS_ROOT), configuration[:application]
- end
-
- def test_user_is_rails
- assert_equal 'rails', configuration[:user]
- end
-
- def test_ruby_is_ree
- assert_equal 'ree', configuration[:ruby]
- end
-
- def test_domain_is_yourapp_dot_com
- assert_equal 'yourapp.com', configuration[:domain]
- end
-
- def test_deploy_rb_has_simple_configuration
- assert_equal "server 'yourapp.com', :app, :web, :db, :primary => true\n", deploy_path.read
- end
-
- def test_deploy_to_uses_application_name
- assert_equal "/srv/#{configuration[:application]}", configuration[:deploy_to]
- end
-
- def test_detects_repository_from_git
- assert_equal configuration[:repository], `git config remote.origin.url`.chomp
- end
-
- private
-
- def configuration
- YAML.load_file(config_path)
- end
-
- def manifest_path
- "#{generator_rails_root}/app/manifests/application_manifest.rb"
- end
-
- def gems_path
- "#{generator_rails_root}/config/gems.yml"
- end
-
- def config_path
- "#{generator_rails_root}/config/moonshine.yml"
- end
-
- def templates_path
- "#{generator_rails_root}/app/manifests/templates"
- end
-
- def capfile_path
- generator_rails_root + 'Capfile'
- end
-
- def deploy_path
- generator_rails_root + 'config' + 'deploy.rb'
- end
-
- def file_list
- Dir.glob("#{generator_rails_root}/*")
- end
-
- end
-end
View
11 test/test_pathname.rb
@@ -1,11 +0,0 @@
-require 'test_helper'
-
-class TestPathname < Test::Unit::TestCase
- def test_match
- assert Pathname.new('/etc') =~ /#{File::SEPARATOR}/
- end
-
- def test_gsub
- assert_equal '/tmp', Pathname.new('/etc').gsub('etc', 'tmp')
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.