summaryrefslogtreecommitdiff
path: root/spec/install/gems/standalone_spec.rb
blob: 16395f0a5ed0bf4ebf2d7092940ff96cf6000351 (plain)
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
require "spec_helper"

describe "bundle install --standalone" do
  describe "with simple gems" do
    before do
      install_gemfile <<-G, :standalone => true
        source "file://#{gem_repo1}"
        gem "rails"
      G
    end

    it "still makes the gems available to normal bundler" do
      should_be_installed "actionpack 2.3.2", "rails 2.3.2"
    end

    it "generates a bundle/bundler/setup.rb" do
      bundled_app("bundle/bundler/setup.rb").should exist
    end

    it "makes the gems available without bundler" do
      ruby <<-RUBY, :no_lib => true
        $:.unshift File.expand_path("bundle")
        require "bundler/setup"

        require "actionpack"
        puts ACTIONPACK
      RUBY

      out.should == "2.3.2"
    end

    it "works on a different system" do
      FileUtils.mv(bundled_app, "#{bundled_app}2")
      Dir.chdir("#{bundled_app}2")

      ruby <<-RUBY, :no_lib => true
        $:.unshift File.expand_path("bundle")
        require "bundler/setup"

        require "actionpack"
        puts ACTIONPACK
      RUBY

      out.should == "2.3.2"
    end
  end

  describe "with a combination of gems and git repos" do
    before do
      build_git "devise", "1.0"

      install_gemfile <<-G, :standalone => true
        source "file://#{gem_repo1}"
        gem "rails"
        gem "devise", :git => "#{lib_path('devise-1.0')}"
      G
    end

    it "still makes the gems available to normal bundler" do
      should_be_installed "actionpack 2.3.2", "rails 2.3.2", "devise 1.0"
    end

    it "generates a bundle/bundler/setup.rb" do
      bundled_app("bundle/bundler/setup.rb").should exist
    end

    it "makes the gems available without bundler" do
      ruby <<-RUBY, :no_lib => true
        $:.unshift File.expand_path("bundle")
        require "bundler/setup"

        require "devise"
        require "actionpack"
        puts DEVISE
        puts ACTIONPACK
      RUBY

      out.should == "1.0\n2.3.2"
    end
  end

  describe "with groups" do
    before do
      build_git "devise", "1.0"

      install_gemfile <<-G, :standalone => true
        source "file://#{gem_repo1}"
        gem "rails"

        group :test do
          gem "rspec"
          gem "rack-test"
        end
      G
    end

    it "makes the gems available without bundler" do
      ruby <<-RUBY, :no_lib => true
        $:.unshift File.expand_path("bundle")
        require "bundler/setup"

        require "actionpack"
        require "spec"
        require "rack/test"
        puts ACTIONPACK
        puts SPEC
        puts RACK_TEST
      RUBY

      out.should == "2.3.2\n1.2.7\n1.0"
    end

    it "allows creating a standalone file with limited groups" do
      bundle "install --standalone default"

      ruby <<-RUBY, :no_lib => true, :expect_err => true
        $:.unshift File.expand_path("bundle")
        require "bundler/setup"

        require "actionpack"
        puts ACTIONPACK
        require "spec"
      RUBY

      out.should == "2.3.2"
      err.should =~ /no such file to load.*spec/
    end

    it "allows --without to limit the groups used in a standalone" do
      bundle "install --standalone --without test"

      ruby <<-RUBY, :no_lib => true, :expect_err => true
        $:.unshift File.expand_path("bundle")
        require "bundler/setup"

        require "actionpack"
        puts ACTIONPACK
        require "spec"
      RUBY

      out.should == "2.3.2"
      err.should =~ /no such file to load.*spec/
    end

    it "allows remembered --without to limit the groups used in a standalone" do
      bundle "install --without test"
      bundle "install --standalone"

      ruby <<-RUBY, :no_lib => true, :expect_err => true
        $:.unshift File.expand_path("bundle")
        require "bundler/setup"

        require "actionpack"
        puts ACTIONPACK
        require "spec"
      RUBY

      out.should == "2.3.2"
      err.should =~ /no such file to load.*spec/
    end
  end
end