|
130 | 130 | expect(install_generator.send(:missing_npm?)).to be true |
131 | 131 | end |
132 | 132 | end |
| 133 | + |
| 134 | + context "when detecting Shakapacker installation" do |
| 135 | + let(:install_generator) { described_class.new } |
| 136 | + |
| 137 | + context "shakapacker_installed?" do |
| 138 | + specify "when Shakapacker gem is installed" do |
| 139 | + mock_gem = double("gem_spec", version: double("version", segments: [7, 0, 0])) |
| 140 | + allow(Gem::Specification).to receive(:find_by_name).with("shakapacker").and_return(mock_gem) |
| 141 | + expect(install_generator.send(:shakapacker_installed?)).to be true |
| 142 | + end |
| 143 | + |
| 144 | + specify "when Shakapacker gem is not installed" do |
| 145 | + allow(Gem::Specification).to receive(:find_by_name).with("shakapacker").and_raise(Gem::MissingSpecError.new("gem", "spec")) |
| 146 | + expect(install_generator.send(:shakapacker_installed?)).to be false |
| 147 | + end |
| 148 | + end |
| 149 | + |
| 150 | + context "ensure_shakapacker_installed" do |
| 151 | + specify "when Shakapacker is already installed" do |
| 152 | + allow(install_generator).to receive(:shakapacker_installed?).and_return(true) |
| 153 | + expect(install_generator).not_to receive(:system) |
| 154 | + install_generator.send(:ensure_shakapacker_installed) |
| 155 | + end |
| 156 | + |
| 157 | + specify "when Shakapacker is not installed and install succeeds" do |
| 158 | + allow(install_generator).to receive(:shakapacker_installed?).and_return(false) |
| 159 | + allow(install_generator).to receive(:system).with("rails shakapacker:install").and_return(true) |
| 160 | + expect(GeneratorMessages).to receive(:add_info).with("Shakapacker not detected. Installing Shakapacker...") |
| 161 | + expect(GeneratorMessages).to receive(:add_info).with("Shakapacker installed successfully!") |
| 162 | + install_generator.send(:ensure_shakapacker_installed) |
| 163 | + end |
| 164 | + |
| 165 | + specify "when Shakapacker is not installed and install fails" do |
| 166 | + allow(install_generator).to receive(:shakapacker_installed?).and_return(false) |
| 167 | + allow(install_generator).to receive(:system).with("rails shakapacker:install").and_return(false) |
| 168 | + expect(GeneratorMessages).to receive(:add_info).with("Shakapacker not detected. Installing Shakapacker...") |
| 169 | + expect(GeneratorMessages).to receive(:add_error).with("Failed to install Shakapacker automatically. Please run 'rails shakapacker:install' manually.") |
| 170 | + install_generator.send(:ensure_shakapacker_installed) |
| 171 | + end |
| 172 | + end |
| 173 | + end |
133 | 174 | end |
0 commit comments