Skip to content
This repository
tree: a979efec70
Fetching contributors…

Cannot retrieve contributors at this time

file 249 lines (216 sloc) 7.181 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
require 'spec_helper'

describe GemTemplate::Gems do
  
  before(:each) do
    @old_config = GemTemplate::Gems.config
    
    GemTemplate::Gems.config.gemspec = "#{$root}/spec/fixtures/gemspec.yml"
    GemTemplate::Gems.config.gemsets = [
      "#{$root}/spec/fixtures/gemsets.yml"
    ]
    GemTemplate::Gems.config.warn = true
    
    GemTemplate::Gems.gemspec true
    GemTemplate::Gems.gemset = nil
  end
  
  after(:each) do
    GemTemplate::Gems.config = @old_config
  end
  
  describe :activate do
    it "should activate gems" do
      GemTemplate::Gems.stub!(:gem)
      GemTemplate::Gems.should_receive(:gem).with('rspec', '=1.3.1')
      GemTemplate::Gems.should_receive(:gem).with('rake', '=0.8.7')
      GemTemplate::Gems.activate :rspec, 'rake'
    end
  end
  
  describe :gemset= do
    before(:each) do
      GemTemplate::Gems.config.gemsets = [
        {
          :name => {
            :rake => '>0.8.6',
            :default => {
              :externals => '=1.0.2'
            }
          }
        },
        "#{$root}/spec/fixtures/gemsets.yml"
      ]
    end
    
    describe :default do
      before(:each) do
        GemTemplate::Gems.gemset = :default
      end
      
      it "should set @gemset" do
        GemTemplate::Gems.gemset.should == :default
      end
    
      it "should set @gemsets" do
        GemTemplate::Gems.gemsets.should == {
          :name => {
            :rake => ">0.8.6",
            :default => {
              :externals => '=1.0.2',
              :mysql => "=2.8.1",
              :rspec => "=1.3.1"
            },
            :rspec2 => {
              :mysql2 => "=0.2.6",
              :rspec => "=2.3.0"
            },
            :solo => nil
          }
        }
      end
    
      it "should set Gems.versions" do
        GemTemplate::Gems.versions.should == {
          :externals => "=1.0.2",
          :mysql => "=2.8.1",
          :rake => ">0.8.6",
          :rspec => "=1.3.1"
        }
      end
      
      it "should return proper values for Gems.dependencies" do
        GemTemplate::Gems.dependencies.should == [ :rake, :mysql ]
        GemTemplate::Gems.development_dependencies.should == []
      end
      
      it "should return proper values for Gems.gemset_names" do
        GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
      end
    end
    
    describe :rspec2 do
      before(:each) do
        GemTemplate::Gems.gemset = "rspec2"
      end
      
      it "should set @gemset" do
        GemTemplate::Gems.gemset.should == :rspec2
      end
    
      it "should set @gemsets" do
        GemTemplate::Gems.gemsets.should == {
          :name => {
            :rake => ">0.8.6",
            :default => {
              :externals => '=1.0.2',
              :mysql => "=2.8.1",
              :rspec => "=1.3.1"
            },
            :rspec2 => {
              :mysql2=>"=0.2.6",
              :rspec => "=2.3.0"
            },
            :solo => nil
          }
        }
      end
    
      it "should set Gems.versions" do
        GemTemplate::Gems.versions.should == {
          :mysql2 => "=0.2.6",
          :rake => ">0.8.6",
          :rspec => "=2.3.0"
        }
      end
      
      it "should return proper values for Gems.dependencies" do
        GemTemplate::Gems.dependencies.should == [ :rake, :mysql2 ]
        GemTemplate::Gems.development_dependencies.should == []
      end
      
      it "should return proper values for Gems.gemset_names" do
        GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
      end
    end
    
    describe :solo do
      before(:each) do
        GemTemplate::Gems.gemset = :solo
      end
      
      it "should set @gemset" do
        GemTemplate::Gems.gemset.should == :solo
      end
    
      it "should set @gemsets" do
        GemTemplate::Gems.gemsets.should == {
          :name => {
            :rake => ">0.8.6",
            :default => {
              :externals => '=1.0.2',
              :mysql => "=2.8.1",
              :rspec => "=1.3.1"
            },
            :rspec2 => {
              :mysql2=>"=0.2.6",
              :rspec => "=2.3.0"
            },
            :solo => nil
          }
        }
      end
    
      it "should set Gems.versions" do
        GemTemplate::Gems.versions.should == {:rake=>">0.8.6"}
      end
      
      it "should return proper values for Gems.dependencies" do
        GemTemplate::Gems.dependencies.should == [:rake]
        GemTemplate::Gems.development_dependencies.should == []
      end
      
      it "should return proper values for Gems.gemset_names" do
        GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
      end
    end
    
    describe :nil do
      before(:each) do
        GemTemplate::Gems.gemset = nil
      end
      
      it "should set everything to nil" do
        GemTemplate::Gems.gemset.should == nil
        GemTemplate::Gems.gemsets.should == nil
        GemTemplate::Gems.versions.should == nil
      end
    end
  end
  
  describe :gemset_from_loaded_specs do
    before(:each) do
      Gem.stub!(:loaded_specs)
    end
    
    it "should return the correct gemset for name gem" do
      Gem.should_receive(:loaded_specs).and_return({ "name" => nil })
      GemTemplate::Gems.send(:gemset_from_loaded_specs).should == :default
    end
    
    it "should return the correct gemset for name-rspec gem" do
      Gem.should_receive(:loaded_specs).and_return({ "name-rspec2" => nil })
      GemTemplate::Gems.send(:gemset_from_loaded_specs).should == :rspec2
    end
  end
  
  describe :reload_gemspec do
    it "should populate @gemspec" do
      GemTemplate::Gems.gemspec.hash.should == {
        "name" => "name",
        "version" => "0.1.0",
        "authors" => ["Author"],
        "email" => "email@email.com",
        "homepage" => "http://github.com/author/name",
        "summary" => "Summary",
        "description" => "Description",
        "dependencies" => [
          "rake",
          { "default" => [ "mysql" ] },
          { "rspec2" => [ "mysql2" ] }
        ],
        "development_dependencies" => nil
       }
    end
  
    it "should create methods from keys of @gemspec" do
      GemTemplate::Gems.gemspec.name.should == "name"
      GemTemplate::Gems.gemspec.version.should == "0.1.0"
      GemTemplate::Gems.gemspec.authors.should == ["Author"]
      GemTemplate::Gems.gemspec.email.should == "email@email.com"
      GemTemplate::Gems.gemspec.homepage.should == "http://github.com/author/name"
      GemTemplate::Gems.gemspec.summary.should == "Summary"
      GemTemplate::Gems.gemspec.description.should == "Description"
      GemTemplate::Gems.gemspec.dependencies.should == [
        "rake",
        { "default" => ["mysql"] },
        { "rspec2" => [ "mysql2" ] }
      ]
      GemTemplate::Gems.gemspec.development_dependencies.should == nil
    end
  
    it "should produce a valid gemspec" do
      GemTemplate::Gems.gemset = :default
      gemspec = File.expand_path("../../../gem_template.gemspec", __FILE__)
      gemspec = eval(File.read(gemspec), binding, gemspec)
      gemspec.validate.should == true
    end
  end
end
Something went wrong with that request. Please try again.