spec/lucid/app_spec.rb in lucid-0.2.1 vs spec/lucid/app_spec.rb in lucid-0.3.0
- old
+ new
@@ -1,24 +1,26 @@
-require_relative '../spec_helper'
+require 'spec_helper'
+require 'lucid/tdl_builder'
+require 'gherkin/formatter/model'
module Lucid
module CLI
describe App do
-
+
let(:args) { [] }
let(:stdin) { StringIO.new }
let(:stdout) { StringIO.new }
let(:stderr) { StringIO.new }
let(:kernel) { double(:kernel) }
subject { App.new(args, stdin, stdout, stderr, kernel) }
-
+
describe 'start' do
context 'passed a runtime' do
let(:runtime) { double('runtime').as_null_object }
def do_start
- subject.start(runtime)
+ subject.start!(runtime)
end
it 'configures the runtime' do
configuration = double('Configuration').as_null_object
Configuration.stub(:new => configuration)
@@ -31,9 +33,76 @@
results = double('results', :failure? => true)
runtime.should_receive(:run)
runtime.stub(:results).and_return(results)
kernel.should_receive(:exit).with(1)
do_start
+ end
+ end
+
+ context 'execution is interrupted' do
+ after do
+ Lucid.wants_to_quit = false
+ end
+
+ it 'should register as a failure' do
+ results = double('results', :failure? => false)
+ runtime = Runtime.any_instance
+ runtime.stub(:run)
+ runtime.stub(:results).and_return(results)
+
+ Lucid.wants_to_quit = true
+ kernel.should_receive(:exit).with(1)
+ subject.start!
+ end
+ end
+ end
+
+ describe 'verbose execution' do
+ before(:each) do
+ b = Lucid::Parser::TDLBuilder.new('specs/test.spec')
+ b.feature(Gherkin::Formatter::Model::Feature.new([], [], 'Feature', 'Testing', '', 99, ''))
+ b.language = double
+ @empty_feature = b.result
+ end
+
+ it 'should show the spec files that were parsed' do
+ cli = App.new(%w{--verbose test.spec}, stdin, stdout, stderr, kernel)
+ cli.stub(:require)
+
+ Lucid::SpecFile.stub(:new).and_return(double('spec file', :parse => @empty_feature))
+ kernel.should_receive(:exit).with(0)
+
+ cli.start!
+
+ stdout.string.should include('test.spec')
+ end
+ end
+
+ describe '--format with a formatter' do
+ it 'should fail if it cannot resolve a Formatter class' do
+ cli = App.new(%w{--format ZooModule::MonkeyFormatterClass}, stdin, stdout, stderr, kernel)
+ mock_module = double('module')
+ Object.stub(:const_defined?).and_return(true)
+ mock_module.stub(:const_defined?).and_return(true)
+
+ f = double('formatter').as_null_object
+
+ Object.should_receive(:const_get).with('ZooModule', false).and_return(mock_module)
+ mock_module.should_receive(:const_get).with('MonkeyFormatterClass', false).and_return(double('formatter class', :new => f))
+
+ kernel.should_receive(:exit).with(1)
+ cli.start!
+ end
+ end
+
+ describe 'handling exceptions' do
+ [ProfilesNotDefinedError, YmlLoadError, ProfileNotFound].each do |exception_class|
+ it "rescues #{exception_class}, prints the message to the error stream" do
+ Configuration.stub(:new).and_return(configuration = double('configuration'))
+ configuration.stub(:parse).and_raise(exception_class.new('error message'))
+
+ subject.start!
+ stderr.string.should == "error message\n"
end
end
end
end
\ No newline at end of file