Skip to content

Commit

Permalink
Added tests for new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mike927 committed Feb 1, 2016
1 parent b9f91de commit caad2a2
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 9 deletions.
7 changes: 5 additions & 2 deletions lib/guard/slimlint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ def run_on_additions(paths)

def run(paths = ['.'])
result = system "slim-lint #{paths.join(' ')}"

if result
UI.info 'No Slim offences detected'.green
else
UI.info 'Slim offences has been detected'.red
end
notify(result) if notification_allowed?(result)
check_and_notify(result)
end

def notification_allowed?(result)
Expand All @@ -52,6 +51,10 @@ def notification_allowed?(result)
end
end

def check_and_notify(result)
notify(result) if notification_allowed?(result)
end

def image(result)
result ? :success : :failed
end
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/slimlint/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Guard
class SlimLintVersion
VERSION = '1.1.2'.freeze
VERSION = '1.2.1'.freeze
end
end
2 changes: 1 addition & 1 deletion spec/fixtures/failfile.html.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
body
p
| This is file
| This is loo long line. This is loo long line. This is loo long line. This is loo long line. This is loo long line.
109 changes: 104 additions & 5 deletions spec/guard/slimlint_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require 'spec_helper'
require 'guard/notifier'
require 'guard/compat/test/helper'
require 'guard/compat/plugin'
require 'guard/slimlint'
require 'colorize'

RSpec.describe Guard::SlimLint do
subject { described_class.new }

before { File.delete("#{@core}/Guardfile") if File.exist?("#{@core}/Guardfile") }
before { system('bundle exec guard init') }
after { File.delete("#{@core}/Guardfile") if File.exist?("#{@core}/Guardfile") }
Expand All @@ -26,11 +24,12 @@
end
end

describe 'run guard' do
describe 'ui loggers' do
subject { described_class.new(notify_on: :none) }

context 'when some offences are found' do
it do
expect(Guard::UI).to receive(:info).with('Slim offences has been detected'.red)
expect(Guard::Notifier).to receive(:notify).with('Slim offences detected', title: 'Slim-lint results', image: :failed)
subject.run_on_modifications([@failfile])
end
end
Expand All @@ -42,4 +41,104 @@
end
end
end

describe 'notifiers' do
context 'when option set on :none' do
subject { described_class.new(notify_on: :none) }

context 'when some offences detected' do
let(:result) { false }

it { expect(subject.send(:notification_allowed?, result)).to eq(false) }
it do
expect(subject).not_to receive(:notify)
subject.send(:check_and_notify, result)
end
end

context 'when no offences detected' do
let(:result) { true }

it { expect(subject.send(:notification_allowed?, result)).to eq(false) }
it do
expect(subject).not_to receive(:notify)
subject.send(:check_and_notify, result)
end
end
end

context 'when option set on :both' do
subject { described_class.new(notify_on: :both) }

context 'when some offences detected' do
let(:result) { false }
it { expect(subject.send(:notification_allowed?, result)).to eq(true) }
it do
expect(subject).to receive(:notify)
subject.send(:check_and_notify, result)
end
end

context 'when no offences detected' do
let(:result) { true }

it { expect(subject.send(:notification_allowed?, result)).to eq(true) }
it do
expect(subject).to receive(:notify)
subject.send(:check_and_notify, result)
end
end
end
end

context 'when option set on :failure' do
subject { described_class.new(notify_on: :failure) }

context 'when some offences detected' do
let(:result) { false }
it { expect(subject.send(:notification_allowed?, result)).to eq(true) }
it do
expect(subject).to receive(:notify)
subject.send(:check_and_notify, result)
end
end

context 'when no offences detected' do
let(:result) { true }

it { expect(subject.send(:notification_allowed?, result)).to eq(false) }
it do
expect(subject).not_to receive(:notify)
subject.send(:check_and_notify, result)
end
end
end

context 'when option set on :success' do
subject { described_class.new(notify_on: :success) }

context 'when some offences detected' do
let(:result) { false }
it { expect(subject.send(:notification_allowed?, result)).to eq(false) }
it do
expect(subject).not_to receive(:notify)
subject.send(:check_and_notify, result)
end
end

context 'when no offences detected' do
let(:result) { true }

it { expect(subject.send(:notification_allowed?, result)).to eq(true) }
it do
expect(subject).to receive(:notify)
subject.send(:check_and_notify, result)
end
end
end

context 'when no option set' do
subject { described_class.new }
it { expect(subject.notify_on).to eq(:failure) }
end
end

0 comments on commit caad2a2

Please sign in to comment.