|
58 | 58 | describe "#swap_base_gem_for_pro_in_gemfile" do |
59 | 59 | let(:generator) { described_class.new } |
60 | 60 | let(:gemfile_path) { File.join(destination_root, "Gemfile") } |
| 61 | + let(:expected_version) { Gem::Version.new(ReactOnRails::VERSION).release.to_s } |
61 | 62 |
|
62 | 63 | before do |
63 | 64 | prepare_destination |
|
74 | 75 | generator.send(:swap_base_gem_for_pro_in_gemfile) |
75 | 76 |
|
76 | 77 | gemfile_content = File.read(gemfile_path) |
77 | | - expected_version = Gem::Version.new(ReactOnRails::VERSION).release.to_s |
78 | 78 | expect(gemfile_content).to include("gem 'react_on_rails_pro', '#{expected_version}'") |
79 | 79 | expect(gemfile_content).not_to match(/gem\s+["']react_on_rails["']/) |
80 | 80 | expect(generator).to have_received(:bundle_install_after_gem_swap) |
81 | 81 | end |
82 | 82 |
|
| 83 | + it "removes react_on_rails when react_on_rails_pro is already present" do |
| 84 | + simulate_existing_file("Gemfile", <<~RUBY) |
| 85 | + source "https://rubygems.org" |
| 86 | + gem "react_on_rails", "~> 16.0" |
| 87 | + gem "react_on_rails_pro", "~> 16.0" |
| 88 | + RUBY |
| 89 | + allow(generator).to receive(:bundle_install_after_gem_swap) |
| 90 | + |
| 91 | + generator.send(:swap_base_gem_for_pro_in_gemfile) |
| 92 | + |
| 93 | + gemfile_content = File.read(gemfile_path) |
| 94 | + pro_gem_lines = gemfile_content.scan(/^\s*gem\s+["']react_on_rails_pro["'][^\n]*$/) |
| 95 | + expect(pro_gem_lines.length).to eq(1) |
| 96 | + expect(gemfile_content).not_to match(/gem\s+["']react_on_rails["']/) |
| 97 | + expect(generator).to have_received(:bundle_install_after_gem_swap) |
| 98 | + end |
| 99 | + |
| 100 | + it "preserves leading whitespace when replacing indented react_on_rails entry" do |
| 101 | + simulate_existing_file("Gemfile", <<~RUBY) |
| 102 | + source "https://rubygems.org" |
| 103 | +
|
| 104 | + group :production do |
| 105 | + gem "react_on_rails", "~> 16.0" |
| 106 | + end |
| 107 | + RUBY |
| 108 | + allow(generator).to receive(:bundle_install_after_gem_swap) |
| 109 | + |
| 110 | + generator.send(:swap_base_gem_for_pro_in_gemfile) |
| 111 | + |
| 112 | + gemfile_content = File.read(gemfile_path) |
| 113 | + expect(gemfile_content).to include(" gem 'react_on_rails_pro', '#{expected_version}'") |
| 114 | + end |
| 115 | + |
83 | 116 | it "does nothing when Gemfile has no react_on_rails entry" do |
84 | 117 | simulate_existing_file("Gemfile", <<~RUBY) |
85 | 118 | source "https://rubygems.org" |
|
0 commit comments