|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | +require 'fileutils' |
| 5 | + |
| 6 | +RSpec.describe NextRails::Init do |
| 7 | + let(:gemfile_content) { "source 'https://rubygems.org'\ngem 'rails'\n" } |
| 8 | + |
| 9 | + before(:all) do |
| 10 | + FileUtils.cp('Gemfile', 'Gemfile.original') |
| 11 | + end |
| 12 | + |
| 13 | + after(:all) do |
| 14 | + FileUtils.cp('Gemfile.original', 'Gemfile') |
| 15 | + FileUtils.rm_f('Gemfile.original') |
| 16 | + end |
| 17 | + |
| 18 | + before do |
| 19 | + FileUtils.rm_f('Gemfile') |
| 20 | + FileUtils.rm_f('Gemfile.lock') |
| 21 | + FileUtils.rm_f('Gemfile.next') |
| 22 | + FileUtils.rm_f('Gemfile.next.lock') |
| 23 | + end |
| 24 | + |
| 25 | + after do |
| 26 | + FileUtils.rm_f('Gemfile') |
| 27 | + FileUtils.rm_f('Gemfile.lock') |
| 28 | + FileUtils.rm_f('Gemfile.next') |
| 29 | + FileUtils.rm_f('Gemfile.next.lock') |
| 30 | + end |
| 31 | + |
| 32 | + describe '.call' do |
| 33 | + it 'already has next Gemfile files' do |
| 34 | + File.write('Gemfile', gemfile_content) |
| 35 | + FileUtils.touch('Gemfile.lock') |
| 36 | + File.write('Gemfile.next', gemfile_content) |
| 37 | + |
| 38 | + expect(described_class.call).to eq('The next_rails --init command has already been run.') |
| 39 | + end |
| 40 | + |
| 41 | + it 'does not have Gemfile files' do |
| 42 | + expect(described_class.call).to eq('You must have a Gemfile and Gemfile.lock to run the next_rails --init command.') |
| 43 | + end |
| 44 | + |
| 45 | + it 'creates Gemfile.next and Gemfile.next.lock' do |
| 46 | + File.write('Gemfile', gemfile_content) |
| 47 | + FileUtils.touch('Gemfile.lock') |
| 48 | + |
| 49 | + expect do |
| 50 | + described_class.call |
| 51 | + end.to change { File.exist?('Gemfile.next') }.from(false).to(true) |
| 52 | + .and change { File.exist?('Gemfile.next.lock') }.from(false).to(true) |
| 53 | + end |
| 54 | + |
| 55 | + it 'returns a success message' do |
| 56 | + File.write('Gemfile', gemfile_content) |
| 57 | + FileUtils.touch('Gemfile.lock') |
| 58 | + |
| 59 | + message = described_class.call |
| 60 | + expect(message).to include('Created Gemfile.next (a symlink to your Gemfile).') |
| 61 | + expect(message).to include("For example, here's how to go from 5.2.8.1 to 6.0.6.1:") |
| 62 | + end |
| 63 | + end |
| 64 | +end |
0 commit comments