Skip to content
This repository
Browse code

Improved test coverage of MoonshineGenerator.

  • Loading branch information...
commit a2e74a6f64cf2f3f3440c56ad696940517ee5a9b 1 parent b419ab4
Josh Nichols authored June 06, 2010
1  generators/moonshine/moonshine_generator.rb
@@ -40,7 +40,6 @@ def manifest
40 40
     recorded_session = record do |m|
41 41
       m.template  'Capfile', 'Capfile'
42 42
       m.directory 'app/manifests'
43  
-      m.directory 'app/manifests/templates'
44 43
       m.template  'moonshine.rb', "app/manifests/#{file_name}.rb"
45 44
       m.directory 'app/manifests/templates'
46 45
       m.template  'readme.templates', 'app/manifests/templates/README'
211  spec/moonshine_generator_spec.rb
... ...
@@ -1,103 +1,184 @@
1 1
 require 'spec_helper'
  2
+require 'yaml'
2 3
 
3 4
 describe MoonshineGenerator do
4 5
   if Rails::VERSION::MAJOR < 3
5  
-    require 'yaml'
6  
-
7  
-    before do
8  
-      FileUtils.mkdir_p(generator_rails_root)
9 6
 
  7
+    def run(*args)
10 8
       lambda {
11  
-        Rails::Generator::Scripts::Generate.new.run(["moonshine"], :destination => generator_rails_root)
  9
+        Dir.chdir generator_rails_root do
  10
+          Rails::Generator::Scripts::Generate.new.run(["moonshine"] + args.flatten, :destination => generator_rails_root)
  11
+        end
12 12
       }.should_not raise_error
13 13
     end
14 14
 
15  
-    after do
16  
-      FileUtils.rm_r(generator_rails_root)
  15
+    before do
  16
+      FileUtils.mkdir_p(generator_rails_root)
17 17
     end
18 18
 
19  
-    it "generates correct files" do
20  
-      capfile_path.should exist
21  
-      manifest_path.should exist
22  
-      templates_path.should exist
23  
-      config_path.should exist
24  
-      gems_path.should exist
25  
-      deploy_path.should exist
  19
+    after do
  20
+      FileUtils.rm_rf(generator_rails_root)
26 21
     end
27 22
 
28  
-    it "generates valid config" do
29  
-      configuration.should be_kind_of(Hash)
30  
-    end
  23
+    context "run with no args" do
  24
+      before do
  25
+        run
  26
+      end
31 27
 
32  
-    it "generates ApplicationManifest as a subclass of Moonshine::Manifest::Rails" do
33  
-      manifest_path.read.should match(/class ApplicationManifest < Moonshine::Manifest::Rails/)
34  
-    end
  28
+      it "generates Capfile" do
  29
+        capfile_path.should exist
  30
+      end
35 31
 
36  
-    it "generates gem dependencies" do
37  
-      YAML.load_file(gems_path).first.should_not == nil
38  
-    end
  32
+      it "generates valid config/moonshine.yml" do
  33
+        moonshine_yml_path.should exist
  34
+        configuration.should be_kind_of(Hash)
  35
+      end
39 36
 
40  
-    it "configures application as rails_root's basename" do
41  
-      configuration[:application].should == File.basename(RAILS_ROOT)
42  
-    end
  37
+      it "generates app/manifests/templates" do
  38
+        templates_path.should exist
  39
+      end
43 40
 
44  
-    it "configures user as 'rails'" do
45  
-      configuration[:user].should == 'rails'
46  
-    end
  41
+      it "generates app/manifets/templates/README" do
  42
+        templates_readme_path.should exist
  43
+      end
47 44
 
48  
-    it "configures ree as the ruby vm" do
49  
-      configuration[:ruby].should == 'ree'
50  
-    end
  45
+      it "generates ApplicationManifest in app/manifests/application_manifest.rb as a subclass of Moonshine::Manifest::Rails" do
  46
+        manifest_path.should exist
  47
+        manifest_path.read.should match(/class ApplicationManifest < Moonshine::Manifest::Rails/)
  48
+      end
51 49
 
52  
-    it "configures a default value for domain" do
53  
-      configuration[:domain].should == 'yourapp.com'
54  
-    end
  50
+      it "generates an initial config/gems.yml" do
  51
+        gems_path.should exist
  52
+        YAML.load_file(gems_path).first.should_not == nil
  53
+      end
55 54
 
56  
-    it "creates a simple config/deploy.rb" do
57  
-      deploy_path.read.should == "server 'yourapp.com', :app, :web, :db, :primary => true\n"
58  
-    end
59  
-    
60  
-    it "configures deploy_to to be under /srv under application" do
61  
-      configuration[:deploy_to].should == "/srv/#{configuration[:application]}"
62  
-    end
  55
+      it "generates config/deploy.rb" do
  56
+        deploy_path.should exist
  57
+      end
63 58
 
64  
-    it "detects repository from `git config remote.origin.url`" do
65  
-      configuration[:repository].should == `git config remote.origin.url`.chomp
66  
-    end
  59
+      it "configures Capistrano to deploy to the default domain in all roles" do
  60
+        deploy_path.read.should include("server 'yourapp.com', :app, :web, :db, :primary => true")
  61
+      end
67 62
 
68  
-    private
  63
+      it "configures application as rails_root's basename" do
  64
+        configuration[:application].should == File.basename(RAILS_ROOT)
  65
+      end
69 66
 
70  
-    def configuration
71  
-      YAML.load_file(config_path)
72  
-    end
  67
+      it "configures user as 'rails'" do
  68
+        configuration[:user].should == 'rails'
  69
+      end
73 70
 
74  
-    def manifest_path
75  
-      generator_rails_root + 'app/manifests/application_manifest.rb'
76  
-    end
  71
+      it "configures ree as the ruby vm" do
  72
+        configuration[:ruby].should == 'ree'
  73
+      end
77 74
 
78  
-    def gems_path
79  
-      generator_rails_root + 'config/gems.yml'
80  
-    end
  75
+      it "configures a default value for domain" do
  76
+        configuration[:domain].should == 'yourapp.com'
  77
+      end
  78
+
  79
+      it "configures a default value for repository" do
  80
+        configuration[:repository].should == 'git@github.com:username/your_app_name.git'
  81
+      end
  82
+
  83
+      it "creates a simple config/deploy.rb" do
  84
+        deploy_path.read.should == "server 'yourapp.com', :app, :web, :db, :primary => true\n"
  85
+      end
  86
+
  87
+      it "configures deploy_to to be under /srv under application" do
  88
+        configuration[:deploy_to].should == "/srv/#{configuration[:application]}"
  89
+      end
  90
+
  91
+      it "configures passenger with 3 workers" do
  92
+        configuration[:passenger][:max_pool_size].should == 3
  93
+      end
  94
+
  95
+      it "configures mysql with 128M innodb buffer pool size" do
  96
+        configuration[:mysql][:innodb_buffer_pool_size].should == "128M"
  97
+      end
81 98
 
82  
-    def config_path
83  
-      generator_rails_root + 'config/moonshine.yml'
84 99
     end
85 100
 
86  
-    def templates_path
87  
-      generator_rails_root + 'app/manifests/templates'
  101
+    context "run in a git repository with an origin" do
  102
+      before do
  103
+        Dir.chdir generator_rails_root do
  104
+          `git init`
  105
+          `git remote add origin git@github.com:zombo/zombo.com.git`
  106
+        end
  107
+
  108
+        run
  109
+      end
  110
+
  111
+      it "detects repository from `git config remote.origin.url`" do
  112
+        configuration[:repository].should == "git@github.com:zombo/zombo.com.git"
  113
+      end
88 114
     end
89 115
 
90  
-    def capfile_path
91  
-      generator_rails_root + 'Capfile'
  116
+    context "run with --user foo" do
  117
+      before do
  118
+        run %w(--user foo)
  119
+      end
  120
+
  121
+      it "configures user as 'foo'" do
  122
+        configuration[:user].should == 'foo'
  123
+      end
92 124
     end
93 125
 
94  
-    def deploy_path
95  
-      generator_rails_root + 'config' + 'deploy.rb'
  126
+    context "run with --domain zombo.com" do
  127
+      before do
  128
+        run %w(--domain zombo.com)
  129
+      end
  130
+
  131
+      it "configures zombo.dom for domain" do
  132
+        configuration[:domain].should == 'zombo.com'
  133
+      end
96 134
     end
97 135
 
98  
-    def file_list
99  
-      Dir.glob("#{generator_rails_root}/*")
  136
+    context "run with --ruby ree187" do
  137
+      before do
  138
+        run %w(--ruby ree187)
  139
+      end
  140
+
  141
+      it "configures ree187 as the ruby vm" do
  142
+        configuration[:ruby].should == 'ree187'
  143
+      end
100 144
     end
  145
+  end
  146
+
  147
+  private
  148
+
  149
+  def configuration
  150
+    YAML.load_file(moonshine_yml_path)
  151
+  end
  152
+
  153
+  def manifest_path
  154
+    generator_rails_root + 'app/manifests/application_manifest.rb'
  155
+  end
  156
+
  157
+  def gems_path
  158
+    generator_rails_root + 'config/gems.yml'
  159
+  end
  160
+
  161
+  def moonshine_yml_path
  162
+    generator_rails_root + 'config/moonshine.yml'
  163
+  end
  164
+
  165
+  def templates_path
  166
+    generator_rails_root + 'app/manifests/templates'
  167
+  end
  168
+
  169
+  def templates_readme_path
  170
+    templates_path + 'README'
  171
+  end
  172
+
  173
+  def capfile_path
  174
+    generator_rails_root + 'Capfile'
  175
+  end
  176
+
  177
+  def deploy_path
  178
+    generator_rails_root + 'config' + 'deploy.rb'
  179
+  end
101 180
 
  181
+  def file_list
  182
+    Dir.glob("#{generator_rails_root}/*")
102 183
   end
103 184
 end
2  spec/support/moonshine_helpers.rb
@@ -17,7 +17,7 @@ def fake_rails_root
17 17
 
18 18
 
19 19
     def generator_rails_root
20  
-      $here.join('generator_rails_root')
  20
+      @generator_rails_root ||= Pathname.new "#{Dir.tmpdir}/moonshine-generator-rails-root-#{Time.now.strftime('%Y%m%d%H%M%S')}" 
21 21
     end
22 22
   end
23 23
 

0 notes on commit a2e74a6

Please sign in to comment.
Something went wrong with that request. Please try again.