|
| 1 | +require "guard/bundler/verify" |
| 2 | + |
| 3 | +RSpec.describe Guard::Bundler::Verify do |
| 4 | + describe '#uses_gemspec?' do |
| 5 | + context "when gemspec is used" do |
| 6 | + before do |
| 7 | + allow(IO).to receive(:read).with('foo').and_return("\n\n gemspec \n") |
| 8 | + end |
| 9 | + |
| 10 | + it "detects used gemspec" do |
| 11 | + expect(subject.uses_gemspec?('foo')).to be_truthy |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + context "when gemspec is not used" do |
| 16 | + before do |
| 17 | + allow(IO).to receive(:read).with('foo').and_return("gem 'rspec'\n") |
| 18 | + end |
| 19 | + |
| 20 | + it "does not detects gemspec usage" do |
| 21 | + expect(subject.uses_gemspec?('foo')).to be_falsey |
| 22 | + end |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + describe '#real_path' do |
| 27 | + context "when Gemfile is not watched" do |
| 28 | + before do |
| 29 | + allow(Guard::Compat).to receive(:watched_directories).and_return(['/foo']) |
| 30 | + end |
| 31 | + |
| 32 | + it 'shows error' do |
| 33 | + expect(Guard::Compat::UI).to receive(:error). |
| 34 | + with(/Guard will not detect changes/) |
| 35 | + subject.real_path('Gemfile') |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + context "when Gemfile is watched along with whole project" do |
| 40 | + before do |
| 41 | + allow(Guard::Compat).to receive(:watched_directories). |
| 42 | + and_return([Pathname.pwd]) |
| 43 | + end |
| 44 | + |
| 45 | + it 'shows no error' do |
| 46 | + expect(Guard::Compat::UI).to_not receive(:error) |
| 47 | + subject.real_path('Gemfile') |
| 48 | + end |
| 49 | + |
| 50 | + it 'returns relative path to file' do |
| 51 | + expect(subject.real_path('Gemfile')).to eq('Gemfile') |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + context "when subdir is watched" do |
| 56 | + before do |
| 57 | + allow(Guard::Compat).to receive(:watched_directories). |
| 58 | + and_return([Pathname.pwd + 'foo']) |
| 59 | + end |
| 60 | + |
| 61 | + context "when Gemfile is symlinked" do |
| 62 | + before do |
| 63 | + allow_any_instance_of(Pathname).to receive(:realpath). |
| 64 | + and_return(Pathname.pwd + 'foo/Gemfile') |
| 65 | + end |
| 66 | + |
| 67 | + it "returns the relative real path" do |
| 68 | + expect(subject.real_path('Gemfile')).to eq('foo/Gemfile') |
| 69 | + end |
| 70 | + |
| 71 | + it 'shows no error' do |
| 72 | + expect(Guard::Compat::UI).to_not receive(:error) |
| 73 | + subject.real_path('Gemfile') |
| 74 | + end |
| 75 | + end |
| 76 | + end |
| 77 | + end |
| 78 | +end |
0 commit comments