From 9de3e2c3939bbc942bafa3902b3fe20de0bd1ad0 Mon Sep 17 00:00:00 2001 From: Nathan Kleyn Date: Sat, 26 Sep 2015 18:19:19 +0100 Subject: [PATCH] Improve test coverage, hopefully back to 100%. --- lib/shanty/env.rb | 2 +- spec/lib/shanty/plugin_spec.rb | 4 +--- .../shanty/plugins/cucumber_plugin_spec.rb | 22 +++++++++++++++++- spec/lib/shanty/plugins/rspec_plugin_spec.rb | 23 ++++++++++++++++++- spec/spec_helper.rb | 14 ++++++++--- 5 files changed, 56 insertions(+), 9 deletions(-) diff --git a/lib/shanty/env.rb b/lib/shanty/env.rb index cda99b7..fe3e990 100644 --- a/lib/shanty/env.rb +++ b/lib/shanty/env.rb @@ -35,7 +35,7 @@ def require! end def logger - @@logger ||= Logger.new(STDOUT).tap do |logger| + @@logger ||= Logger.new($stdout).tap do |logger| logger.formatter = proc do |_, datetime, _, msg| "#{datetime}: #{msg}\n" end diff --git a/spec/lib/shanty/plugin_spec.rb b/spec/lib/shanty/plugin_spec.rb index 1dfa7f5..d128b61 100644 --- a/spec/lib/shanty/plugin_spec.rb +++ b/spec/lib/shanty/plugin_spec.rb @@ -8,9 +8,7 @@ module Shanty let(:graph) { double('graph') } let(:plugin_class) do Class.new(described_class) do - def foo - [] - end + def foo; end end end subject { plugin_class.new } diff --git a/spec/lib/shanty/plugins/cucumber_plugin_spec.rb b/spec/lib/shanty/plugins/cucumber_plugin_spec.rb index ed741c4..8f72584 100644 --- a/spec/lib/shanty/plugins/cucumber_plugin_spec.rb +++ b/spec/lib/shanty/plugins/cucumber_plugin_spec.rb @@ -4,7 +4,7 @@ # All classes referenced belong to the shanty project module Shanty RSpec.describe(CucumberPlugin) do - include_context('basics') + include_context('graph') it('adds the cucumber tag') do expect(described_class).to add_tags(:cucumber) @@ -18,6 +18,26 @@ module Shanty expect(described_class).to subscribe_to(:test).with(:cucumber) end + describe('#cucumber_projects') do + it('returns projects with a dependency on Cucumber in a Gemfile') do + File.write(File.join(project_paths[:one], 'Gemfile'), "gem 'cucumber', '~> 1.2.3'") + + expect(subject.cucumber_projects).to match_array([projects[:one]]) + end + + it('returns projects with a dependency on Cucumber in a *.gemspec') do + File.write(File.join(project_paths[:two], 'foo.gemspec'), "gem.add_dependency 'cucumber', '~> 1.2.3") + + expect(subject.cucumber_projects).to match_array([projects[:two]]) + end + + it('does not return projects with no dependency on Cucumber') do + File.write(File.join(project_paths[:three], 'Gemfile'), "gem 'foo', '~> 1.2.3'") + + expect(subject.cucumber_projects).to be_empty + end + end + describe('#cucumber') do it('calls cucumber') do expect(subject).to receive(:system).with('cucumber') diff --git a/spec/lib/shanty/plugins/rspec_plugin_spec.rb b/spec/lib/shanty/plugins/rspec_plugin_spec.rb index 06c3ae0..9e44846 100644 --- a/spec/lib/shanty/plugins/rspec_plugin_spec.rb +++ b/spec/lib/shanty/plugins/rspec_plugin_spec.rb @@ -1,10 +1,11 @@ +require 'fileutils' require 'spec_helper' require 'shanty/plugins/rspec_plugin' # All classes referenced belong to the shanty project module Shanty RSpec.describe(RspecPlugin) do - include_context('basics') + include_context('graph') it('adds the rspec tag') do expect(described_class).to add_tags(:rspec) @@ -18,6 +19,26 @@ module Shanty expect(described_class).to subscribe_to(:test).with(:rspec) end + describe('#rspec_projects') do + it('returns projects with a dependency on RSpec in a Gemfile') do + File.write(File.join(project_paths[:one], 'Gemfile'), "gem 'rspec', '~> 1.2.3'") + + expect(subject.rspec_projects).to match_array([projects[:one]]) + end + + it('returns projects with a dependency on RSpec in a *.gemspec') do + File.write(File.join(project_paths[:two], 'foo.gemspec'), "gem.add_dependency 'rspec', '~> 1.2.3") + + expect(subject.rspec_projects).to match_array([projects[:two]]) + end + + it('does not return projects with no dependency on RSpec') do + File.write(File.join(project_paths[:three], 'Gemfile'), "gem 'foo', '~> 1.2.3'") + + expect(subject.rspec_projects).to be_empty + end + end + describe('#rspec') do it('calls rspec') do expect(subject).to receive(:system).with('rspec') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 29fd119..e00e0fe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,7 +28,7 @@ def require_matchers(path) I18n.enforce_available_locales = false RSpec.configure do |config| - config.expect_with :rspec do |c| + config.expect_with(:rspec) do |c| c.include_chain_clauses_in_custom_matcher_descriptions = true end @@ -36,12 +36,20 @@ def require_matchers(path) mocks.verify_partial_doubles = true end + # Supress any writing to stdout or stderr during the tests. We don't want + # any of the logging to be written in between our test output. + config.around(:all) do |example| + $stderr = File.open(File::NULL, 'w') + $stdout = File.open(File::NULL, 'w') + example.run + $stderr = STDERR + $stdout = STDOUT + end + config.before(:example) do Shanty::Env.clear! Shanty::TaskEnv.clear! Shanty::Project.clear! - - Shanty::Env.logger.level = Logger::FATAL end end