spec/guard/reek_spec.rb in guard-reek-0.0.4 vs spec/guard/reek_spec.rb in guard-reek-1.0.1

- old
+ new

@@ -1,96 +1,96 @@ require 'spec_helper' describe Guard::Reek do - subject { reek } - let(:guard) { described_class.new } + subject { described_class.new options } + let(:options) { { runner: runner, ui: ui } } + let(:ui) { class_double('Guard::UI', info: true) } + let(:runner) { instance_double('Guard::Reek::Runner') } - before do - Guard::Notifier.stub :notify + describe '#start' do + def start + subject.start + end - Guard::UI.stub :info - Guard::UI.stub :error - end + it 'runs by default' do + expect(runner).to receive(:run).with(no_args) + start + end - describe "#start" do - subject(:start) { guard.start } + it 'wont run when all_on_start is false' do + options[:all_on_start] = false + expect(runner).to_not receive(:run) + start + end - it "runs all" do - guard.should_receive :run_all - + it 'runs when all_on_start is true' do + options[:all_on_start] = true + expect(runner).to receive(:run).with(no_args) start end + + it 'raises :task_has_failed if runner throws exception' do + allow(runner).to receive(:run).and_raise(RuntimeError) + expect { start }.to raise_exception(UncaughtThrowError) + end end - describe "#run_all" do - subject(:run_all) { guard.run_all } + describe '#run_all' do + def run_all + subject.run_all + end - it "runs reek" do - described_class.should_receive(:reek).with([]) - + it 'runs by default' do + expect(runner).to receive(:run).with(no_args) run_all end - end - describe "#run_on_changes" do - subject(:run_on_changes) { guard.run_on_changes "path" } - - it "runs changed paths" do - described_class.should_receive(:reek).with("path") - - run_on_changes + it 'wont run when run_all is false' do + options[:run_all] = false + expect(runner).to_not receive(:run) + run_all end - end - describe ".reek" do - before do - described_class.stub(:system) - described_class.stub(:command) - described_class.stub(:system).and_return(true) + it 'runs when all_on_start is true' do + options[:run_all] = true + expect(runner).to receive(:run).with(no_args) + run_all end - subject(:reek) { described_class.reek("paths") } - - it "calls the system" do - described_class.should_receive(:system) + it 'raises :task_has_failed if runner throws exception' do + allow(runner).to receive(:run).and_raise(RuntimeError) + expect { run_all }.to raise_exception(UncaughtThrowError) end + end - it "calls the reek command" do - described_class.should_receive(:command).with("paths") + describe '#run_on_additions' do + def run_on_additions(paths) + subject.run_on_additions(paths) end - it "notifies guard the ddsuccess" do - described_class.should_receive(:notify) + it 'runs by default' do + expect(runner).to receive(:run).with(['lib/myfile.rb']) + run_on_additions(['lib/myfile.rb']) end - after do - reek + it 'raises :task_has_failed if runner throws exception' do + allow(runner).to receive(:run).and_raise(RuntimeError) + expect { run_on_additions(['lib/myfile.rb']) }.to raise_exception(UncaughtThrowError) end end - describe ".command" do - subject(:command) { described_class.command ["path"] } - it { should =~ /-n/ } - it { should =~ /^reek/ } - it { should =~ /path$/ } - end + describe '#run_on_modifications' do + def run_on_modifications(paths) + subject.run_on_modifications(paths) + end - describe ".notify" do - context "well done" do - subject(:notify) { described_class.notify true } - it "notifies the success to notifier" do - Guard::Notifier.should_receive(:notify).with(*Guard::Reek::SUCCESS) - - notify - end + it 'runs by default' do + expect(runner).to receive(:run).with(['lib/myfile.rb']) + run_on_modifications(['lib/myfile.rb']) end - context "something went wrong" do - subject(:notify) { described_class.notify false } - it "notifies the failure to notifier" do - Guard::Notifier.should_receive(:notify).with(*Guard::Reek::FAILED) - - notify - end + it 'raises :task_has_failed if runner throws exception' do + allow(runner).to receive(:run).and_raise(RuntimeError) + expect { run_on_modifications(['lib/myfile.rb']) }.to raise_exception(UncaughtThrowError) end end end