|  | 
| 28 | 28 |     } | 
| 29 | 29 |   end | 
| 30 | 30 | 
 | 
|  | 31 | +  let(:mock_logger) { instance_double(Logger, error: nil, info: nil) } | 
|  | 32 | +  let(:mock_root) { instance_double(Pathname, join: config_file_path) } | 
|  | 33 | +  let(:config_file_path) { instance_double(Pathname, exist?: false) } | 
|  | 34 | + | 
| 31 | 35 |   before do | 
| 32 | 36 |     described_class.reset! | 
| 33 | 37 |     # Stub the public key constant to use our test key | 
| 34 | 38 |     stub_const("ReactOnRailsPro::LicensePublicKey::KEY", test_public_key) | 
| 35 | 39 |     # Clear ENV variable | 
| 36 | 40 |     ENV.delete("REACT_ON_RAILS_PRO_LICENSE") | 
|  | 41 | + | 
|  | 42 | +    # Stub Rails.logger to avoid nil errors in unit tests | 
|  | 43 | +    allow(Rails).to receive(:logger).and_return(mock_logger) | 
|  | 44 | +    # Stub Rails.root for config file path tests | 
|  | 45 | +    allow(Rails).to receive(:root).and_return(mock_root) | 
| 37 | 46 |   end | 
| 38 | 47 | 
 | 
| 39 | 48 |   after do | 
|  | 
| 89 | 98 |       end | 
| 90 | 99 | 
 | 
| 91 | 100 |       it "raises error" do | 
| 92 |  | -        expect { described_class.valid? }.to raise_error(ReactOnRailsPro::Error, /License is missing required expiration field/) | 
|  | 101 | +        expect { described_class.valid? } | 
|  | 102 | +          .to raise_error(ReactOnRailsPro::Error, /License is missing required expiration field/) | 
| 93 | 103 |       end | 
| 94 | 104 | 
 | 
| 95 | 105 |       it "includes FREE license information in error message" do | 
|  | 
| 114 | 124 |     end | 
| 115 | 125 | 
 | 
| 116 | 126 |     context "with missing license" do | 
| 117 |  | -      let(:config_path) { double("Pathname", exist?: false) } | 
| 118 |  | - | 
| 119 | 127 |       before do | 
| 120 | 128 |         ENV.delete("REACT_ON_RAILS_PRO_LICENSE") | 
| 121 |  | -        allow(Rails.root).to receive(:join).with("config", "react_on_rails_pro_license.key").and_return(config_path) | 
|  | 129 | +        # config_file_path is already set to exist?: false in the let block | 
| 122 | 130 |       end | 
| 123 | 131 | 
 | 
| 124 | 132 |       it "raises error" do | 
| 125 | 133 |         expect { described_class.valid? }.to raise_error(ReactOnRailsPro::Error, /No license found/) | 
| 126 | 134 |       end | 
| 127 | 135 | 
 | 
| 128 | 136 |       it "includes FREE license information in error message" do | 
| 129 |  | -        expect { described_class.valid? }.to raise_error(ReactOnRailsPro::Error, /FREE evaluation license/) | 
|  | 137 | +        expect { described_class.valid? } | 
|  | 138 | +          .to raise_error(ReactOnRailsPro::Error, /FREE evaluation license/) | 
| 130 | 139 |       end | 
| 131 | 140 |     end | 
| 132 | 141 | 
 | 
| 133 | 142 |     context "with license in config file" do | 
| 134 |  | -      let(:config_path) { Rails.root.join("config", "react_on_rails_pro_license.key") } | 
| 135 | 143 |       let(:valid_token) { JWT.encode(valid_payload, test_private_key, "RS256") } | 
|  | 144 | +      let(:file_config_path) { instance_double(Pathname, exist?: true) } | 
| 136 | 145 | 
 | 
| 137 | 146 |       before do | 
| 138 | 147 |         ENV.delete("REACT_ON_RAILS_PRO_LICENSE") | 
| 139 |  | -        allow(config_path).to receive(:exist?).and_return(true) | 
| 140 |  | -        allow(File).to receive(:read).with(config_path).and_return(valid_token) | 
|  | 148 | +        allow(mock_root).to receive(:join) | 
|  | 149 | +          .with("config", "react_on_rails_pro_license.key") | 
|  | 150 | +          .and_return(file_config_path) | 
|  | 151 | +        allow(File).to receive(:read).with(file_config_path).and_return(valid_token) | 
| 141 | 152 |       end | 
| 142 | 153 | 
 | 
| 143 | 154 |       it "returns true" do | 
|  | 
0 commit comments