From 8fe0690064ab6251e53e23b21b9abd49242da1c7 Mon Sep 17 00:00:00 2001 From: Stephen Lloyd-Hirst Date: Thu, 21 Apr 2016 12:07:14 +0100 Subject: [PATCH 1/4] Run rubocop auto correct on spec --- .rubocop.yml | 2 + Fudgefile | 14 ++--- Guardfile | 4 +- Rakefile | 2 +- bin/fudge | 1 - fudge.gemspec | 18 +++--- spec/lib/fudge/build_spec.rb | 23 ++++--- spec/lib/fudge/cli_spec.rb | 55 ++++++++--------- spec/lib/fudge/description_spec.rb | 68 ++++++++++----------- spec/lib/fudge/exceptions_spec.rb | 4 +- spec/lib/fudge/formatters/simple_spec.rb | 63 ++++++++++--------- spec/lib/fudge/output_checker_spec.rb | 18 +++--- spec/lib/fudge/parser_spec.rb | 4 +- spec/lib/fudge/runner_spec.rb | 20 +++--- spec/lib/fudge/tasks/brakeman_spec.rb | 5 +- spec/lib/fudge/tasks/bundler_spec.rb | 9 ++- spec/lib/fudge/tasks/cane_spec.rb | 22 +++---- spec/lib/fudge/tasks/composite_task_spec.rb | 18 +++--- spec/lib/fudge/tasks/cucumber_spec.rb | 13 ++-- spec/lib/fudge/tasks/each_directory_spec.rb | 18 +++--- spec/lib/fudge/tasks/flay_spec.rb | 11 ++-- spec/lib/fudge/tasks/flog_spec.rb | 18 +++--- spec/lib/fudge/tasks/in_directory_spec.rb | 6 +- spec/lib/fudge/tasks/rake_spec.rb | 4 +- spec/lib/fudge/tasks/rspec_spec.rb | 25 ++++---- spec/lib/fudge/tasks/shell_spec.rb | 41 ++++++------- spec/lib/fudge/tasks/sub_process_spec.rb | 40 ++++++------ spec/lib/fudge/tasks/task_spec.rb | 40 ++++++------ spec/lib/fudge/tasks/yard_spec.rb | 6 +- spec/lib/fudge/tasks_spec.rb | 8 +-- spec/lib/fudge/with_directory_spec.rb | 4 +- spec/spec_helper.rb | 2 +- spec/support/dummy_task.rb | 2 +- 33 files changed, 288 insertions(+), 300 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..59b273c --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +Metrics/LineLength: + Max: 120 diff --git a/Fudgefile b/Fudgefile index 29c5798..1a2b92a 100644 --- a/Fudgefile +++ b/Fudgefile @@ -1,21 +1,21 @@ task_group :spec do - task :rspec, :coverage => 100 + task :rspec, coverage: 100 end task_group :docs do - task :yard, :coverage => 100 + task :yard, coverage: 100 end task_group :codestyle do - task :cane, :max_width => 150 + task :cane, max_width: 150 end task_group :duplication do - task :flay, :exclude => '^\.\/spec\/', :max => 42 + task :flay, exclude: '^\.\/spec\/', max: 42 end task_group :complexity do - task :flog, :exclude => '^\.\/spec\/', :max => 13, :average => 4.1, :methods => true + task :flog, exclude: '^\.\/spec\/', max: 13, average: 4.1, methods: true end task_group :shout_about_success do @@ -35,7 +35,7 @@ task_group :shout_about_success_and_failure do task_group :shout_about_failure end -build :default, :about => 'Runs unit tests, and checks test coverage, documentation coverage, and code style and complexity' do +build :default, about: 'Runs unit tests, and checks test coverage, documentation coverage, and code style and complexity' do task_group :spec task_group :docs task_group :codestyle @@ -45,7 +45,7 @@ build :default, :about => 'Runs unit tests, and checks test coverage, documentat task_group :shout_about_success_and_failure end -build :nodoc, :about => 'Runs unit tests' do +build :nodoc, about: 'Runs unit tests' do task_group :spec task_group :shout_about_success_and_failure diff --git a/Guardfile b/Guardfile index 7b8e09a..a81bd96 100644 --- a/Guardfile +++ b/Guardfile @@ -1,5 +1,5 @@ -guard 'rspec', :version => 2 do +guard 'rspec', version: 2 do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } - watch('spec/spec_helper.rb') { "spec" } + watch('spec/spec_helper.rb') { 'spec' } end diff --git a/Rakefile b/Rakefile index 6ebfdde..f15a87b 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -task :default => :fudge +task default: :fudge # Test Fudge using Fudge task :fudge do diff --git a/bin/fudge b/bin/fudge index 4060461..cd6245a 100755 --- a/bin/fudge +++ b/bin/fudge @@ -6,4 +6,3 @@ rescue Fudge::Exceptions::Base => e puts e.message exit 1 end - diff --git a/fudge.gemspec b/fudge.gemspec index ea38b0d..4f14fa5 100644 --- a/fudge.gemspec +++ b/fudge.gemspec @@ -1,28 +1,28 @@ # -*- encoding: utf-8 -*- -$:.push File.expand_path('../lib', __FILE__) +$LOAD_PATH.push File.expand_path('../lib', __FILE__) require 'fudge/version' Gem::Specification.new do |s| s.name = 'fudge' s.version = Fudge::VERSION - s.authors = %q{Sage One team} - s.email = %q{support@sageone.com} - s.homepage = %q{http://github.com/Sage/fudge} - s.summary = %q{Fudge CI Server} - s.description = %q{Fudge Continuous Integration Server} + s.authors = 'Sage One team' + s.email = 'support@sageone.com' + s.homepage = 'http://github.com/Sage/fudge' + s.summary = 'Fudge CI Server' + s.description = 'Fudge Continuous Integration Server' s.license = 'MIT' s.files = Dir['lib/**/*'] s.test_files = Dir['spec/**/*.rb'] - s.executables = %w{fudge} - s.require_paths = %w{lib} + s.executables = %w(fudge) + s.require_paths = %w(lib) s.add_dependency 'thor' s.add_dependency 'json' s.add_development_dependency 'redcarpet' s.add_development_dependency 'rspec', '>= 3.0.0' s.add_development_dependency 'guard-rspec' - s.add_development_dependency 'rb-fsevent' #guard dependency + s.add_development_dependency 'rb-fsevent' # guard dependency s.add_development_dependency 'yard' s.add_development_dependency 'cane' s.add_development_dependency 'flog' diff --git a/spec/lib/fudge/build_spec.rb b/spec/lib/fudge/build_spec.rb index 6dfe40f..f71525b 100644 --- a/spec/lib/fudge/build_spec.rb +++ b/spec/lib/fudge/build_spec.rb @@ -3,19 +3,18 @@ describe Fudge::Build do it { is_expected.to be_a Fudge::Tasks::CompositeTask } - describe "#run" do - - context "when provided an output" do + describe '#run' do + context 'when provided an output' do let(:stdout) { StringIO.new } let(:formatter) { Fudge::Formatters::Simple.new(stdout) } - it "prints messages to the formatter instead of default" do - subject.run :formatter => formatter + it 'prints messages to the formatter instead of default' do + subject.run formatter: formatter expect(stdout.string).to be_empty end - context "when there are callback hooks" do + context 'when there are callback hooks' do let(:hook) { double(:Hook) } before :each do @@ -23,24 +22,24 @@ subject.success_hooks << hook end - it "passesformatter down to the hook run" do - expect(hook).to receive(:run).with(:formatter =>formatter).and_return(true) - subject.run :formatter => formatter + it 'passesformatter down to the hook run' do + expect(hook).to receive(:run).with(formatter: formatter).and_return(true) + subject.run formatter: formatter end end - context "when the `time` flag is set" do + context 'when the `time` flag is set' do before do subject.callbacks = true allow(subject).to receive(:run_callbacks).and_return(true) subject.time = true end - it "should print out the time of the build" do + it 'should print out the time of the build' do expect(subject).to receive(:message) do |message| expect(message).to match /Finished in \d+.\d\d seconds./ end - subject.run :formatter => formatter + subject.run formatter: formatter end end end diff --git a/spec/lib/fudge/cli_spec.rb b/spec/lib/fudge/cli_spec.rb index 94e08f9..26d5281 100644 --- a/spec/lib/fudge/cli_spec.rb +++ b/spec/lib/fudge/cli_spec.rb @@ -5,7 +5,7 @@ def self.name :another_dummy end - def run(options={}) + def run(_options = {}) self.class.ran = true end end @@ -18,7 +18,7 @@ def run(options={}) AnotherDummyTask.ran = false end - describe ".build" do + describe '.build' do before :each do contents = <<-RUBY build :default do @@ -33,15 +33,15 @@ def run(options={}) allow(File).to receive(:open) { |&block| block.yield file } end - context "when not given a build name" do - it "runs the default build" do + context 'when not given a build name' do + it 'runs the default build' do subject.build 'default' expect(DummyTask.ran).to be_truthy end end - context "when given a build name" do - it "runs the only the named build" do + context 'when given a build name' do + it 'runs the only the named build' do subject.build 'other' expect(DummyTask.ran).to be_falsey expect(AnotherDummyTask.ran).to be_truthy @@ -49,13 +49,13 @@ def run(options={}) end end - describe ".init" do + describe '.init' do let (:file_state) { { exists: false, content: '' } } let (:override_file_state) do - ->(exists, content) { + lambda do |exists, content| file_state[:exists] = exists file_state[:content] = content - } + end end before :each do @@ -74,8 +74,8 @@ def run(options={}) allow(subject).to receive(:shell).and_return(shell) end - context "when a Fudgefile does not exist in the current directory" do - it "creates a new FudgeFile" do + context 'when a Fudgefile does not exist in the current directory' do + it 'creates a new FudgeFile' do expect(File).not_to be_exists('Fudgefile') subject.init @@ -83,7 +83,7 @@ def run(options={}) expect(File).to be_exists('Fudgefile') end - it "writes a default build into the new Fudgefile" do + it 'writes a default build into the new Fudgefile' do subject.init File.open('Fudgefile', 'r') do |f| @@ -91,33 +91,33 @@ def run(options={}) end end - it "outputs a success message" do + it 'outputs a success message' do subject.init expect(@output).to eq 'Fudgefile created.' end end - context "when a Fudgefile already exists in the current directory" do + context 'when a Fudgefile already exists in the current directory' do before :each do - override_file_state.(true, 'foo') + override_file_state.call(true, 'foo') end - it "does not modify the existing Fudgefile" do + it 'does not modify the existing Fudgefile' do expect(File).to be_exists('Fudgefile') subject.init - expect(File.open('Fudgefile') { |f| f.read }).to eql 'foo' + expect(File.open('Fudgefile', &:read)).to eql 'foo' end - it "outputs a failure message" do + it 'outputs a failure message' do subject.init expect(@output).to eq 'Fudgefile already exists.' end end end - describe ".list" do + describe '.list' do before :each do contents = <<-RUBY build :default do @@ -137,32 +137,31 @@ def run(options={}) allow(subject).to receive(:shell).and_return(shell) end - context "when not given a filter string" do - it "lists all the defined builds" do + context 'when not given a filter string' do + it 'lists all the defined builds' do subject.list expect(@output).to eql "default\t\nother\tnot the default" end end - context "when given a filter string" do - context "that matches one or builds" do - it "lists only the builds that match the filter" do + context 'when given a filter string' do + context 'that matches one or builds' do + it 'lists only the builds that match the filter' do subject.list 'oth' expect(@output).to eql "other\tnot the default" end - it "ignores the case of the filter" do + it 'ignores the case of the filter' do subject.list 'OTH' expect(@output).to eql "other\tnot the default" end end - context "that matches no builds" do - it "outputs nothing" do + context 'that matches no builds' do + it 'outputs nothing' do expect(@output).to eql '' end end end end - end diff --git a/spec/lib/fudge/description_spec.rb b/spec/lib/fudge/description_spec.rb index 8b4e670..e227102 100644 --- a/spec/lib/fudge/description_spec.rb +++ b/spec/lib/fudge/description_spec.rb @@ -8,7 +8,6 @@ let(:build) { subject.builds.values.first } let(:build_tasks) { build.tasks.dup } - def make_build subject.build :default do subject.task :dummy @@ -17,16 +16,16 @@ def make_build build.callbacks = callbacks end - describe "#initialize" do + describe '#initialize' do let(:input) { 'build :foo do; end' } - it "should add the builds in the given string" do + it 'should add the builds in the given string' do expect(subject.builds[:foo]).to be_a Fudge::Build end end - describe "#build" do - it "should create a new build and add it to the builds array" do + describe '#build' do + it 'should create a new build and add it to the builds array' do expect(subject.builds).to be_empty subject.build :some_branch do @@ -37,8 +36,8 @@ def make_build end end - describe "#task" do - it "should add a task to the current scope" do + describe '#task' do + it 'should add a task to the current scope' do subject.build :default do subject.task :dummy end @@ -47,7 +46,7 @@ def make_build expect(build_tasks.first).to be_a DummyTask end - it "should pass arguments to the initializer" do + it 'should pass arguments to the initializer' do subject.build :default do subject.task :dummy, :foo, :bar end @@ -55,7 +54,7 @@ def make_build expect(build_tasks.first.args).to eq([:foo, :bar]) end - it "should forward missing methods to task" do + it 'should forward missing methods to task' do subject.build :default do subject.dummy :foo, :bar end @@ -63,11 +62,11 @@ def make_build expect(build_tasks.first.args).to eq([:foo, :bar]) end - it "should super method_missing if no task found" do + it 'should super method_missing if no task found' do expect { subject.no_task :foo, :bar }.to raise_error(NoMethodError) end - it "should add tasks recursively to composite tasks" do + it 'should add tasks recursively to composite tasks' do subject.build :default do subject.dummy_composite do subject.dummy @@ -78,8 +77,8 @@ def make_build end end - describe "#task_group" do - it "should add a task group and allow it to be used in a build" do + describe '#task_group' do + it 'should add a task group and allow it to be used in a build' do subject.task_group :group1 do subject.task :dummy end @@ -92,7 +91,7 @@ def make_build expect(DummyTask.ran).to be_truthy end - it "should allow passing arguments to task groups" do + it 'should allow passing arguments to task groups' do subject.task_group :special_group do |which| subject.task which end @@ -105,7 +104,7 @@ def make_build expect(DummyTask.ran).to be_truthy end - it "should raise an exception if task group not found" do + it 'should raise an exception if task group not found' do expect do subject.build :default do subject.task_group :unkown_group @@ -113,14 +112,14 @@ def make_build end.to raise_error Fudge::Exceptions::TaskGroupNotFound end - context "grouped tasks" do + context 'grouped tasks' do before :each do subject.task_group :group1 do subject.task :dummy end end - it "allows group task reuse in composite tasks" do + it 'allows group task reuse in composite tasks' do subject.build :default do subject.task :dummy_composite do subject.task_group :group1 @@ -131,9 +130,9 @@ def make_build expect(DummyTask.ran).to be_truthy end - it "supports when options are given" do + it 'supports when options are given' do subject.build :default do - subject.task :dummy_composite, :hello, :foobar => true do + subject.task :dummy_composite, :hello, foobar: true do subject.task_group :group1 end end @@ -146,10 +145,9 @@ def make_build expect(DummyTask.ran).to be_truthy end end - end - describe "Callback Hooks" do + describe 'Callback Hooks' do before :each do @ran = [] allow_any_instance_of(Fudge::Tasks::Shell).to receive(:run_command) do |cmd| @@ -158,21 +156,21 @@ def make_build end end - describe "#on_success" do - context "when callbacks is set to true" do + describe '#on_success' do + context 'when callbacks is set to true' do let(:callbacks) { true } - it "should add success hooks that run after the build is successful" do + it 'should add success hooks that run after the build is successful' do make_build do subject.on_success { subject.shell 'FOO' } subject.on_success { subject.shell 'BAR' } end expect(build.run).to be_truthy - expect(@ran).to eq(['FOO', 'BAR']) + expect(@ran).to eq(%w(FOO BAR)) end - it "fails the build HARD when hooks fail" do + it 'fails the build HARD when hooks fail' do make_build do subject.on_success { subject.shell 'fail'; subject.shell 'FOO' } subject.on_success { subject.shell 'BAR' } @@ -183,10 +181,10 @@ def make_build end end - context "when callbacks is set to false" do + context 'when callbacks is set to false' do let(:callbacks) { false } - it "should not run the callbacks if the build succeeds" do + it 'should not run the callbacks if the build succeeds' do make_build do subject.on_success { subject.shell 'echo "WOOP"' } end @@ -197,25 +195,25 @@ def make_build end end - describe "#on_failure" do + describe '#on_failure' do before :each do allow_any_instance_of(DummyTask).to receive(:run).and_return(false) end - context "when callbacks is set to true" do + context 'when callbacks is set to true' do let(:callbacks) { true } - it "should add failure hooks that run after the build fails" do + it 'should add failure hooks that run after the build fails' do make_build do subject.on_failure { subject.shell 'WOOP' } subject.on_failure { subject.shell 'BAR' } end expect(build.run).to be_falsey - expect(@ran).to eq(['WOOP', 'BAR']) + expect(@ran).to eq(%w(WOOP BAR)) end - it "fails the build HARD when hooks fail" do + it 'fails the build HARD when hooks fail' do make_build do subject.on_failure { subject.shell 'fail'; subject.shell 'FOO' } subject.on_failure { subject.shell 'BAR' } @@ -226,10 +224,10 @@ def make_build end end - context "when callbacks is set to false" do + context 'when callbacks is set to false' do let(:callbacks) { false } - it "should not run the callbacks if the build fails" do + it 'should not run the callbacks if the build fails' do make_build do subject.on_failure { subject.shell 'WOOP' } end diff --git a/spec/lib/fudge/exceptions_spec.rb b/spec/lib/fudge/exceptions_spec.rb index 1e8b604..56e16ae 100644 --- a/spec/lib/fudge/exceptions_spec.rb +++ b/spec/lib/fudge/exceptions_spec.rb @@ -24,7 +24,7 @@ module Fudge::Exceptions it { is_expected.to be_a String } end - it "should take a task name as a parameter" do + it 'should take a task name as a parameter' do expect { described_class.new }.to raise_error ArgumentError end end @@ -39,7 +39,7 @@ module Fudge::Exceptions it { is_expected.to be_a String } end - it "should take a task group name as a parameter" do + it 'should take a task group name as a parameter' do expect { described_class.new }.to raise_error ArgumentError end end diff --git a/spec/lib/fudge/formatters/simple_spec.rb b/spec/lib/fudge/formatters/simple_spec.rb index 7a57601..faf6c42 100644 --- a/spec/lib/fudge/formatters/simple_spec.rb +++ b/spec/lib/fudge/formatters/simple_spec.rb @@ -5,64 +5,63 @@ subject { described_class.new(stdout) } - describe "#error" do - it "returns message in RED" do - string = subject.error "a message" + describe '#error' do + it 'returns message in RED' do + string = subject.error 'a message' expect(string).to eq("\e[31ma message\e[0m") end end - describe "#success" do - it "returns message in BRIGHT GREEN" do - string = subject.success "a message" + describe '#success' do + it 'returns message in BRIGHT GREEN' do + string = subject.success 'a message' expect(string).to eq("\e[1m\e[32ma message\e[0m") end end - describe "#info" do - it "returns message in CYAN" do - string = subject.info "a message" + describe '#info' do + it 'returns message in CYAN' do + string = subject.info 'a message' expect(string).to eq("\e[36ma message\e[0m") end end - describe "#notice" do - it "returns message in YELLOW" do - string = subject.notice "a message" + describe '#notice' do + it 'returns message in YELLOW' do + string = subject.notice 'a message' expect(string).to eq("\e[33ma message\e[0m") end end - describe "#normal" do - it "returns unchanged message" do - string = subject.normal "a message" - expect(string).to eq("a message") + describe '#normal' do + it 'returns unchanged message' do + string = subject.normal 'a message' + expect(string).to eq('a message') end end - describe "#puts" do - it "outputs message on stdout" do - subject.puts "a message" - expect(stdout.string).to eq("a message" + "\n") + describe '#puts' do + it 'outputs message on stdout' do + subject.puts 'a message' + expect(stdout.string).to eq('a message' + "\n") end end - describe "#write" do - it "supports chaining types to stdout" do + describe '#write' do + it 'supports chaining types to stdout' do subject.write do |w| - w.normal('normal'). - notice('notice'). - info('info'). - success('success'). - error('error') + w.normal('normal') + .notice('notice') + .info('info') + .success('success') + .error('error') end - expect(stdout.string).to eq('normal' + ' ' + - "\e[33mnotice\e[0m" + ' ' + - "\e[36minfo\e[0m" + ' ' + - "\e[1m\e[32msuccess\e[0m" + ' ' + + expect(stdout.string).to eq('normal' + ' ' \ + "\e[33mnotice\e[0m" + ' ' \ + "\e[36minfo\e[0m" + ' ' \ + "\e[1m\e[32msuccess\e[0m" + ' ' \ "\e[31merror\e[0m" + "\n") - end end end diff --git a/spec/lib/fudge/output_checker_spec.rb b/spec/lib/fudge/output_checker_spec.rb index 21ff09f..dfc24f9 100644 --- a/spec/lib/fudge/output_checker_spec.rb +++ b/spec/lib/fudge/output_checker_spec.rb @@ -4,19 +4,19 @@ let(:output_io) { StringIO.new } let(:formatter) { Fudge::Formatters::Simple.new(output_io) } - describe "#check" do + describe '#check' do subject { described_class.new(/foo/, formatter) } - context "when the output does not match the check" do - it 'send a mismatch message to the output io' do - subject.check('bar') - expect(output_io.string).to include "Output didn't match (?-mix:foo)." - end + context 'when the output does not match the check' do + it 'send a mismatch message to the output io' do + subject.check('bar') + expect(output_io.string).to include "Output didn't match (?-mix:foo)." + end end - context "with a block for checking" do + context 'with a block for checking' do let(:callable) do - Proc.new do + proc do false end end @@ -25,7 +25,7 @@ it 'sends error mesage to the output io' do subject.check('foo') - expect(output_io.string).to include "Output matched (?-mix:foo) but condition failed." + expect(output_io.string).to include 'Output matched (?-mix:foo) but condition failed.' end end end diff --git a/spec/lib/fudge/parser_spec.rb b/spec/lib/fudge/parser_spec.rb index aba8659..bd0cfb4 100644 --- a/spec/lib/fudge/parser_spec.rb +++ b/spec/lib/fudge/parser_spec.rb @@ -12,11 +12,11 @@ end end - it "should read a file and evaluate it" do + it 'should read a file and evaluate it' do expect(subject.parse(@path)).to be_a Fudge::Description end - it "should pass the contents to the new description" do + it 'should pass the contents to the new description' do expect(subject.parse(@path).instance_variable_get(:@foo)).to eq(:bar) end end diff --git a/spec/lib/fudge/runner_spec.rb b/spec/lib/fudge/runner_spec.rb index 1279050..8805257 100644 --- a/spec/lib/fudge/runner_spec.rb +++ b/spec/lib/fudge/runner_spec.rb @@ -10,35 +10,35 @@ subject { described_class.new(description) } describe '#run_build' do - it "should run the default task in the description" do + it 'should run the default task in the description' do subject.run_build expect(DummyTask.ran).to be_truthy end - it "should raise an exception if the build fails" do + it 'should raise an exception if the build fails' do allow_any_instance_of(Fudge::Build).to receive(:run).and_return(false) expect { subject.run_build }.to raise_error Fudge::Exceptions::BuildFailed end - context "when an formatter is provided" do + context 'when an formatter is provided' do let(:stdout) { StringIO.new } let(:formatter) { Fudge::Formatters::Simple.new(stdout) } before :each do - subject.run_build 'default', :formatter => formatter + subject.run_build 'default', formatter: formatter end - it "puts all output to given formatter instead stdout" do + it 'puts all output to given formatter instead stdout' do expect(stdout.string).not_to be_empty - expect(stdout.string).to include "Running build" - expect(stdout.string).to include "default" - expect(stdout.string).to include "Build SUCCEEDED!" + expect(stdout.string).to include 'Running build' + expect(stdout.string).to include 'default' + expect(stdout.string).to include 'Build SUCCEEDED!' end - it "runs the task passing the formatter down" do - expect(DummyTask.run_options).to eq({:formatter => formatter}) + it 'runs the task passing the formatter down' do + expect(DummyTask.run_options).to eq(formatter: formatter) end end end diff --git a/spec/lib/fudge/tasks/brakeman_spec.rb b/spec/lib/fudge/tasks/brakeman_spec.rb index 282029a..b935b87 100644 --- a/spec/lib/fudge/tasks/brakeman_spec.rb +++ b/spec/lib/fudge/tasks/brakeman_spec.rb @@ -5,7 +5,6 @@ it_should_behave_like 'bundle aware' - let(:output_good) do <<-EOF | Errors | 0 | @@ -50,10 +49,10 @@ context 'when :max score is supplied' do it 'fails when score is higher than max' do - task = described_class.new :max => 0 + task = described_class.new max: 0 expect(task).not_to succeed_with_output output_bad - task = described_class.new :max => 1 + task = described_class.new max: 1 expect(task).to succeed_with_output output_bad end end diff --git a/spec/lib/fudge/tasks/bundler_spec.rb b/spec/lib/fudge/tasks/bundler_spec.rb index 399a6d2..0bd9793 100644 --- a/spec/lib/fudge/tasks/bundler_spec.rb +++ b/spec/lib/fudge/tasks/bundler_spec.rb @@ -11,12 +11,11 @@ def run(options = {}) end class TestNonBundlerAwareTask - def self.name :test_non_bundle_aware end - def run(options={}) + def run(_options = {}) true end end @@ -28,15 +27,15 @@ def run(options={}) let(:bundle_aware_task) { TestBundlerAwareTask.new } let(:non_bundle_aware_task) { TestNonBundlerAwareTask.new } - context "with a bundle aware task" do - it "should run the bundle dependent tasks successfully" do + context 'with a bundle aware task' do + it 'should run the bundle dependent tasks successfully' do subject.tasks << bundle_aware_task subject.tasks << non_bundle_aware_task expect(subject.run).to be_truthy end - it "runs each task with a clean bundle env" do + it 'runs each task with a clean bundle env' do expect(Bundler).to receive(:with_clean_env).and_call_original subject.tasks << bundle_aware_task diff --git a/spec/lib/fudge/tasks/cane_spec.rb b/spec/lib/fudge/tasks/cane_spec.rb index 7daf727..34c2371 100644 --- a/spec/lib/fudge/tasks/cane_spec.rb +++ b/spec/lib/fudge/tasks/cane_spec.rb @@ -6,31 +6,31 @@ it_should_behave_like 'bundle aware' describe '#run' do - it "runs cane on the codebase" do - expect(subject).to run_command "cane" + it 'runs cane on the codebase' do + expect(subject).to run_command 'cane' end context 'with :doc => false' do - subject {described_class.new :doc => false } + subject { described_class.new doc: false } - it "runs with --no-doc" do - expect(subject).to run_command "cane --no-doc" + it 'runs with --no-doc' do + expect(subject).to run_command 'cane --no-doc' end end context 'with :style => false' do - subject {described_class.new :style => false } + subject { described_class.new style: false } - it "runs with --no-style" do - expect(subject).to run_command "cane --no-style" + it 'runs with --no-style' do + expect(subject).to run_command 'cane --no-style' end end context 'with :max_width => 100' do - subject {described_class.new :max_width => 100 } + subject { described_class.new max_width: 100 } - it "runs with --style-measure 100" do - expect(subject).to run_command "cane --style-measure 100" + it 'runs with --style-measure 100' do + expect(subject).to run_command 'cane --style-measure 100' end end diff --git a/spec/lib/fudge/tasks/composite_task_spec.rb b/spec/lib/fudge/tasks/composite_task_spec.rb index f4616e3..3fb864a 100644 --- a/spec/lib/fudge/tasks/composite_task_spec.rb +++ b/spec/lib/fudge/tasks/composite_task_spec.rb @@ -8,7 +8,7 @@ def self.name Fudge::Tasks.register(DummyTask2) describe Fudge::Tasks::CompositeTask do - subject { described_class.new do; end } + subject { described_class.new { ; } } describe '#run' do before :each do @@ -19,20 +19,20 @@ def self.name allow_any_instance_of(DummyTask2).to receive(:run) { |*_| @task_two_run = true } end - it "should run all tasks defined and return true if they all succeed" do + it 'should run all tasks defined and return true if they all succeed' do expect_any_instance_of(DummyTask).to receive(:run).and_return(true) expect(subject.run).to be_truthy expect(@task_two_run).to be_truthy end - it "should return false if any of the tasks fail" do + it 'should return false if any of the tasks fail' do expect_any_instance_of(DummyTask).to receive(:run).and_return(false) expect(subject.run).to be_falsey expect(@task_two_run).to be_falsey end end - describe "Using TaskDSL" do + describe 'Using TaskDSL' do describe '#task' do class AnotherCompositeTask < Fudge::Tasks::CompositeTask include Fudge::TaskDSL @@ -49,15 +49,15 @@ def initialize(*args) subject { AnotherCompositeTask.new } - it "should define a task for each new instance of the composite task" do + it 'should define a task for each new instance of the composite task' do expect(subject).to run_command 'foo bar' end - it "should support defining composite tasks" do + it 'should support defining composite tasks' do expect(subject.tasks[1].tasks.first).to be_a DummyTask end - context "when provided an output" do + context 'when provided an output' do let(:output) { StringIO.new } let(:formatter) { Fudge::Formatters::Simple.new(output) } @@ -65,8 +65,8 @@ def initialize(*args) allow_any_instance_of(Fudge::Tasks::Shell).to receive(:run) end - it "prints messages to the output instead of stdout" do - subject.run :formatter => formatter + it 'prints messages to the output instead of stdout' do + subject.run formatter: formatter expect(output.string).not_to be_empty expect(output.string).to match /Running task.*shell.*foo, bar/ diff --git a/spec/lib/fudge/tasks/cucumber_spec.rb b/spec/lib/fudge/tasks/cucumber_spec.rb index ab957a3..4e1a339 100644 --- a/spec/lib/fudge/tasks/cucumber_spec.rb +++ b/spec/lib/fudge/tasks/cucumber_spec.rb @@ -9,31 +9,30 @@ end it 'turns off color if specified' do - expect(described_class.new(:color => false)).not_to run_command /--color/ + expect(described_class.new(color: false)).not_to run_command /--color/ end it 'appends any arguments passed in' do - task = described_class.new('foobar', :color => false) + task = described_class.new('foobar', color: false) expect(task).to run_command 'cucumber foobar' end it 'should default the arguments to spec/' do - expect(described_class.new(:color => false)).to run_command 'cucumber features/' + expect(described_class.new(color: false)).to run_command 'cucumber features/' end - end it_should_behave_like 'bundle aware' describe '#coverage' do - subject { described_class.new :coverage => 99 } + subject { described_class.new coverage: 99 } it { is_expected.not_to succeed_with_output 'some dummy output with no coverage' } it { is_expected.not_to succeed_with_output '98.99999%) covered' } it { is_expected.not_to succeed_with_output '0.00%) covered' } it { is_expected.to succeed_with_output '99.99999%) covered' } it { is_expected.to succeed_with_output '100.0%) covered' } - it { is_expected.to succeed_with_output "Finished in 0.1 seconds\n70 examples, 0 failures\n700 / 700 LOC (100.0%) covered."} - it { is_expected.not_to succeed_with_output "Finished in 0.6 seconds\n70 examples, 0 failures\n384 / 700 LOC (54.86%) covered."} + it { is_expected.to succeed_with_output "Finished in 0.1 seconds\n70 examples, 0 failures\n700 / 700 LOC (100.0%) covered." } + it { is_expected.not_to succeed_with_output "Finished in 0.6 seconds\n70 examples, 0 failures\n384 / 700 LOC (54.86%) covered." } end end diff --git a/spec/lib/fudge/tasks/each_directory_spec.rb b/spec/lib/fudge/tasks/each_directory_spec.rb index 86014a8..ddde426 100644 --- a/spec/lib/fudge/tasks/each_directory_spec.rb +++ b/spec/lib/fudge/tasks/each_directory_spec.rb @@ -6,7 +6,7 @@ def self.name :test_each_directory end - def run(options={}) + def run(_options = {}) (self.pwds ||= []) << FileUtils.pwd end end @@ -17,7 +17,7 @@ def run(options={}) it { is_expected.to be_registered_as :each_directory } describe '#initialize' do - it "should take a directory pattern as first argument" do + it 'should take a directory pattern as first argument' do expect { described_class.new }.to raise_error ArgumentError end end @@ -33,35 +33,35 @@ def run(options={}) subject.tasks << task end - it "should change to the given directories and run child tasks" do + it 'should change to the given directories and run child tasks' do subject.run expect(task.pwds).to eq(dirs) end - it "should allow explicit specification of directories through an array" do - ed2 = described_class.new ["spec/lib","spec/support"] + it 'should allow explicit specification of directories through an array' do + ed2 = described_class.new ['spec/lib', 'spec/support'] ed2.tasks << task ed2.run expect(task.pwds).to eq(dirs.sort) end - it "should respect the order of the directories as specified" do - ed2 = described_class.new ["spec/support","spec/lib"] + it 'should respect the order of the directories as specified' do + ed2 = described_class.new ['spec/support', 'spec/lib'] ed2.tasks << task ed2.run expect(task.pwds).not_to eq(dirs.sort) expect(task.pwds.sort).to eq(dirs.sort) end - it "should load fudge_settings.yml in the right directory" do + it 'should load fudge_settings.yml in the right directory' do ed2 = described_class.new ['spec/lib'] ed2.tasks << Fudge::Tasks::Shell.new('pwd') ed2.run expect(ed2.tasks.first.options[:test]).to eq('coverage') end - it "should not load fudge_settings.yml in the wrong directory" do + it 'should not load fudge_settings.yml in the wrong directory' do ed2 = described_class.new ['spec/support'] ed2.tasks << Fudge::Tasks::Shell.new('pwd') ed2.run diff --git a/spec/lib/fudge/tasks/flay_spec.rb b/spec/lib/fudge/tasks/flay_spec.rb index ef06078..8fd253f 100644 --- a/spec/lib/fudge/tasks/flay_spec.rb +++ b/spec/lib/fudge/tasks/flay_spec.rb @@ -5,7 +5,6 @@ it_should_behave_like 'bundle aware' - let(:output_good) do <<-EOF Total score (lower is better) = 0 @@ -19,15 +18,15 @@ end describe '#run' do - it "runs flay on the codebase" do + it 'runs flay on the codebase' do expect(subject).to run_command "flay --diff `find . | grep --color=never -e '\\.rb$'`" end context 'with :exclude => pattern' do - subject {described_class.new :exclude => 'spec/'} + subject { described_class.new exclude: 'spec/' } # Test doesn't check result :( - it "filters out the pattern" do + it 'filters out the pattern' do cmd = "flay --diff `find . | grep --color=never -e '\\.rb$' | grep --color=never -v -E 'spec/'`" expect(subject).to run_command cmd end @@ -38,10 +37,10 @@ context 'when :max score is supplied' do it 'fails when score is higher than max' do - task = described_class.new :max => 99 + task = described_class.new max: 99 expect(task).not_to succeed_with_output output_bad - task = described_class.new :max => 100 + task = described_class.new max: 100 expect(task).to succeed_with_output output_bad end end diff --git a/spec/lib/fudge/tasks/flog_spec.rb b/spec/lib/fudge/tasks/flog_spec.rb index aea484e..b9faabe 100644 --- a/spec/lib/fudge/tasks/flog_spec.rb +++ b/spec/lib/fudge/tasks/flog_spec.rb @@ -46,24 +46,24 @@ end describe '#run' do - it "runs flog on the codebase" do + it 'runs flog on the codebase' do expect(subject).to run_command "flog `find . | grep --color=never -e '\\.rb$'`" end context 'with :exclude => pattern' do - subject {described_class.new :exclude => 'spec/'} + subject { described_class.new exclude: 'spec/' } # Test doesn't check result :( - it "filters out the pattern" do + it 'filters out the pattern' do with_pattern = "flog `find . | grep --color=never -e '\\.rb$' | grep --color=never -v -E 'spec/'`" expect(subject).to run_command with_pattern end end context 'with :methods => true' do - subject {described_class.new :methods => true} + subject { described_class.new methods: true } - it "runs with methods only flag" do + it 'runs with methods only flag' do with_pattern = "flog -m `find . | grep --color=never -e '\\.rb$'`" expect(subject).to run_command with_pattern end @@ -76,20 +76,20 @@ context 'when :max score is supplied' do it 'fails when score is higher than max' do - task = described_class.new :max => 9.9 + task = described_class.new max: 9.9 expect(task).not_to succeed_with_output output_good - task = described_class.new :max => 10.0 + task = described_class.new max: 10.0 expect(task).to succeed_with_output output_good end end context 'when :average score is supplied' do it 'fails when average is higher than :average' do - task = described_class.new :average => 4.9 + task = described_class.new average: 4.9 expect(task).not_to succeed_with_output output_good - task = described_class.new :average => 5.0 + task = described_class.new average: 5.0 expect(task).to succeed_with_output output_good end end diff --git a/spec/lib/fudge/tasks/in_directory_spec.rb b/spec/lib/fudge/tasks/in_directory_spec.rb index 36ffa74..06b68ea 100644 --- a/spec/lib/fudge/tasks/in_directory_spec.rb +++ b/spec/lib/fudge/tasks/in_directory_spec.rb @@ -6,7 +6,7 @@ def self.name :test_in_directory end - def run(options={}) + def run(_options = {}) self.pwd = FileUtils.pwd end end @@ -17,7 +17,7 @@ def run(options={}) it { is_expected.to be_registered_as :in_directory } describe '#initialize' do - it "should take a directory as first argument" do + it 'should take a directory as first argument' do expect { described_class.new }.to raise_error ArgumentError end end @@ -30,7 +30,7 @@ def run(options={}) subject.tasks << task end - it "should change to the given directory and run child tasks" do + it 'should change to the given directory and run child tasks' do subject.run expect(task.pwd).to eq(path) diff --git a/spec/lib/fudge/tasks/rake_spec.rb b/spec/lib/fudge/tasks/rake_spec.rb index f250154..b4ffe1d 100644 --- a/spec/lib/fudge/tasks/rake_spec.rb +++ b/spec/lib/fudge/tasks/rake_spec.rb @@ -5,13 +5,13 @@ it { is_expected.to be_a Fudge::Tasks::Shell } describe '#run' do - it "should be rake by default" do + it 'should be rake by default' do expect(subject).to run_command 'rake ' end it_should_behave_like 'bundle aware' - it "should add any arguments given" do + it 'should add any arguments given' do expect(described_class.new('db:migrate')).to run_command 'rake db:migrate' end end diff --git a/spec/lib/fudge/tasks/rspec_spec.rb b/spec/lib/fudge/tasks/rspec_spec.rb index 0b4921f..f848d4e 100644 --- a/spec/lib/fudge/tasks/rspec_spec.rb +++ b/spec/lib/fudge/tasks/rspec_spec.rb @@ -4,38 +4,37 @@ it { is_expected.to be_registered_as :rspec } describe '#run' do - it "should turn on color if not specified" do + it 'should turn on color if not specified' do expect(subject).to run_command /--tty/ end - it "should turn off color if specified" do - expect(described_class.new(:color => false)).not_to run_command /--tty/ + it 'should turn off color if specified' do + expect(described_class.new(color: false)).not_to run_command /--tty/ end - it "should append any arguments passed in" do - task = described_class.new('foobar', :color => false) + it 'should append any arguments passed in' do + task = described_class.new('foobar', color: false) expect(task).to run_command 'rspec foobar' end - it "should default the arguments to spec/" do - expect(described_class.new(:color => false)).to run_command 'rspec spec/' + it 'should default the arguments to spec/' do + expect(described_class.new(color: false)).to run_command 'rspec spec/' end - end it_should_behave_like 'bundle aware' describe '#coverage' do - subject { described_class.new :coverage => 99 } + subject { described_class.new coverage: 99 } it { is_expected.not_to succeed_with_output 'some dummy output with no coverage' } it { is_expected.not_to succeed_with_output '98.99999%) covered' } it { is_expected.not_to succeed_with_output '0.00%) covered' } it { is_expected.to succeed_with_output '99.99999%) covered' } it { is_expected.to succeed_with_output '100.0%) covered' } - it { is_expected.to succeed_with_output "\n0 examples, 0 failures"} - it { is_expected.to succeed_with_output "No examples found.\n\n\nFinished in 0.00006 seconds\n\e[32m0 examples, 0 failures\e[0m\n"} - it { is_expected.to succeed_with_output "Finished in 0.1 seconds\n70 examples, 0 failures\n700 / 700 LOC (100.0%) covered."} - it { is_expected.not_to succeed_with_output "Finished in 0.6 seconds\n70 examples, 0 failures\n384 / 700 LOC (54.86%) covered."} + it { is_expected.to succeed_with_output "\n0 examples, 0 failures" } + it { is_expected.to succeed_with_output "No examples found.\n\n\nFinished in 0.00006 seconds\n\e[32m0 examples, 0 failures\e[0m\n" } + it { is_expected.to succeed_with_output "Finished in 0.1 seconds\n70 examples, 0 failures\n700 / 700 LOC (100.0%) covered." } + it { is_expected.not_to succeed_with_output "Finished in 0.6 seconds\n70 examples, 0 failures\n384 / 700 LOC (54.86%) covered." } end end diff --git a/spec/lib/fudge/tasks/shell_spec.rb b/spec/lib/fudge/tasks/shell_spec.rb index 5f4e267..c911562 100644 --- a/spec/lib/fudge/tasks/shell_spec.rb +++ b/spec/lib/fudge/tasks/shell_spec.rb @@ -2,63 +2,60 @@ describe Fudge::Tasks::Shell do describe '#run' do - it "should take a command and run it" do + it 'should take a command and run it' do expect(described_class.new(:ls)).to run_command 'ls' end - it "should add any arguments given" do + it 'should add any arguments given' do expect(described_class.new(:ls, '-l', '-a')).to run_command 'ls -l -a' end - it "should return false for an unsuccessful command" do + it 'should return false for an unsuccessful command' do expect(described_class.new(:ls, '--newnre').run).to be_falsey end - it "should return true for a successful command" do + it 'should return true for a successful command' do expect(described_class.new(:ls).run).to be_truthy end - context "when there is an formatter passed to run" do - + context 'when there is an formatter passed to run' do let(:output) { StringIO.new } let(:formatter) { Fudge::Formatters::Simple.new(output) } subject { described_class.new('echo foo') } - it "prints messages to the formatter instead of default" do - - subject.run :formatter => formatter + it 'prints messages to the formatter instead of default' do + subject.run formatter: formatter expect(output.string).not_to be_empty - expect(output.string).to include "foo" + expect(output.string).to include 'foo' end it 'uses the formatter when reporting checks on build result' do checker = double.as_null_object expect(Fudge::OutputChecker).to receive(:new).with(anything, formatter) { checker } - subject.run :formatter => formatter + subject.run formatter: formatter end - end end describe '#check_for' do - context "with no callable to check the matches" do - subject { described_class.new(:ls, :check_for => /4 files found/) } + context 'with no callable to check the matches' do + subject { described_class.new(:ls, check_for: /4 files found/) } - it { is_expected.to succeed_with_output "Hello there were 4 files found." } - it { is_expected.not_to succeed_with_output "Hellow there were 5 files found." } + it { is_expected.to succeed_with_output 'Hello there were 4 files found.' } + it { is_expected.not_to succeed_with_output 'Hellow there were 5 files found.' } end - context "with a callable to check the matches" do - let(:file_count_matcher) { lambda { |matches| matches[1].to_i >= 4 }} + context 'with a callable to check the matches' do + let(:file_count_matcher) { ->(matches) { matches[1].to_i >= 4 } } subject do described_class.new :ls, - :check_for => [/(\d+) files found/, file_count_matcher] + check_for: [/(\d+) files found/, file_count_matcher] end - it { is_expected.not_to succeed_with_output "Hello there were 3 files found." } - it { is_expected.to succeed_with_output "Hello there were 4 files found." } - it { is_expected.to succeed_with_output "Hellow there were 5 files found." } + it { is_expected.not_to succeed_with_output 'Hello there were 3 files found.' } + it { is_expected.to succeed_with_output 'Hello there were 4 files found.' } + it { is_expected.to succeed_with_output 'Hellow there were 5 files found.' } end end end diff --git a/spec/lib/fudge/tasks/sub_process_spec.rb b/spec/lib/fudge/tasks/sub_process_spec.rb index e9d6c4c..f7ec2d6 100644 --- a/spec/lib/fudge/tasks/sub_process_spec.rb +++ b/spec/lib/fudge/tasks/sub_process_spec.rb @@ -6,25 +6,25 @@ let(:formatter) { Fudge::Formatters::Simple.new(output) } describe '#run' do - it "takes a command and runs it" do + it 'takes a command and runs it' do expect(described_class.new(:ls)).to run_command [{}, 'ls', {}] end - it "adds any arguments given" do + it 'adds any arguments given' do expect(described_class.new(:ls, '-l', '-a')).to run_command [{}, 'ls', '-l', '-a', {}] end - it "returns false for an unsuccessful command" do + it 'returns false for an unsuccessful command' do expect(described_class.new(:ls, '--newnre').run).to be_falsey end - it "returns true for a successful command" do + it 'returns true for a successful command' do expect(described_class.new(:ls).run).to be_truthy end - context "when given environment variables" do - context "when the task is created" do - it "passes the variables to the sub-process" do + context 'when given environment variables' do + context 'when the task is created' do + it 'passes the variables to the sub-process' do process = described_class.new(%(ruby -e "puts ENV['PATH'];puts ENV['FOO']"), environment: { 'FOO' => 'bar' }) process.run(formatter: formatter) @@ -33,8 +33,8 @@ end end - context "when the task is run" do - it "passes the variables to the sub-process" do + context 'when the task is run' do + it 'passes the variables to the sub-process' do process = described_class.new(%(ruby -e "puts ENV['PATH'];puts ENV['FOO']")) process.run(formatter: formatter, environment: { 'FOO' => 'bar' }) @@ -43,8 +43,8 @@ end end - context "when the task is created and when it is run" do - it "gives priority to the variables passed in on run" do + context 'when the task is created and when it is run' do + it 'gives priority to the variables passed in on run' do process = described_class.new(%(ruby -e "puts ENV['FOO'];puts ENV['BAZ']"), environment: { 'FOO' => 'bar', 'BAZ' => 'quux' }) @@ -55,8 +55,8 @@ end end - context "when not given an environment variable" do - it "does not make that variable available to the sub-process" do + context 'when not given an environment variable' do + it 'does not make that variable available to the sub-process' do process = described_class.new(%(ruby -e "puts ENV['FOO']")) process.run(formatter: formatter) @@ -65,9 +65,9 @@ end end - context "when given spawn options" do - context "when the task is created" do - it "applies those options to the sub-process" do + context 'when given spawn options' do + context 'when the task is created' do + it 'applies those options to the sub-process' do process = described_class.new(%(ruby -e "puts ENV['PATH'];puts ENV['FOO']"), environment: { 'FOO' => 'bar' }, spawn_options: { unsetenv_others: true }) # Should clear environment variables @@ -78,8 +78,8 @@ end end - context "when the task is run" do - it "applies those options to the sub-process" do + context 'when the task is run' do + it 'applies those options to the sub-process' do process = described_class.new(%(ruby -e "puts ENV['PATH'];puts ENV['FOO']"), environment: { 'FOO' => 'bar' }) @@ -89,8 +89,8 @@ end end - context "when the task is created and when it is run" do - it "gives priority to the options passed in on run" do + context 'when the task is created and when it is run' do + it 'gives priority to the options passed in on run' do process = described_class.new(%(ruby -e "puts ENV['PATH'];puts ENV['FOO']"), environment: { 'FOO' => 'bar' }, spawn_options: { unsetenv_others: true }) # Clear environment variables diff --git a/spec/lib/fudge/tasks/task_spec.rb b/spec/lib/fudge/tasks/task_spec.rb index 528e776..62f8bc8 100644 --- a/spec/lib/fudge/tasks/task_spec.rb +++ b/spec/lib/fudge/tasks/task_spec.rb @@ -4,7 +4,7 @@ class MyTask < Fudge::Tasks::Task attr_accessor :cod attr_accessor :_methods_missing - def method_missing(method, *args) + def method_missing(method, *_args) (@_methods_missing ||= []).push(method) end end @@ -16,56 +16,56 @@ class SomeTask < Fudge::Tasks::Task describe Fudge::Tasks::Task do describe :initialize do - context "given arguments" do - it "accepts and stores the arguments" do + context 'given arguments' do + it 'accepts and stores the arguments' do task = MyTask.new :foo, :bar, :baz expect(task.args).to match_array [:foo, :bar, :baz] end end - context "given options" do - let (:task) { MyTask.new :cod => 'fanglers' } + context 'given options' do + let (:task) { MyTask.new cod: 'fanglers' } - it "accepts and sets the options" do + it 'accepts and sets the options' do expect(task.cod).to eq 'fanglers' end - it "accepts and stores the options" do - expect(task.options).to eq({ cod: 'fanglers' }) + it 'accepts and stores the options' do + expect(task.options).to eq(cod: 'fanglers') end - context "including an option that is not supported" do - let (:task) { MyTask.new :cod => 'fanglers', :foo => 'bar' } + context 'including an option that is not supported' do + let (:task) { MyTask.new cod: 'fanglers', foo: 'bar' } - it "ignores the unsupported options" do + it 'ignores the unsupported options' do expect(task._methods_missing).to be_nil end - it "stores all provided options" do - expect(task.options).to eq({ cod: 'fanglers', foo: 'bar' }) + it 'stores all provided options' do + expect(task.options).to eq(cod: 'fanglers', foo: 'bar') end end end - context "given arguments and options" do - let (:task) { MyTask.new :foo, :bar, :cod => 'fanglers' } + context 'given arguments and options' do + let (:task) { MyTask.new :foo, :bar, cod: 'fanglers' } - it "stores the arguments separately from the options" do + it 'stores the arguments separately from the options' do expect(task.args).to match_array [:foo, :bar] end - it "applies the options" do + it 'applies the options' do expect(task.cod).to eq 'fanglers' end - it "stores the options separately from the arguments" do - expect(task.options).to eq({ cod: 'fanglers' }) + it 'stores the options separately from the arguments' do + expect(task.options).to eq(cod: 'fanglers') end end end describe :name do - it "should default to implied name from class name" do + it 'should default to implied name from class name' do expect(TestNamespace::SomeTask.name).to eq(:some_task) end end diff --git a/spec/lib/fudge/tasks/yard_spec.rb b/spec/lib/fudge/tasks/yard_spec.rb index c859ecd..62740e2 100644 --- a/spec/lib/fudge/tasks/yard_spec.rb +++ b/spec/lib/fudge/tasks/yard_spec.rb @@ -6,11 +6,11 @@ it { is_expected.to be_registered_as :yard } describe '#run' do - it "runs stats with undocumented by default" do + it 'runs stats with undocumented by default' do expect(subject).to run_command 'yard stats --list-undoc' end - it "should run yard with any arguments passed in" do + it 'should run yard with any arguments passed in' do task = described_class.new('-r YardREADME.md') expect(task).to run_command 'yard -r YardREADME.md' end @@ -19,7 +19,7 @@ it_should_behave_like 'bundle aware' describe '#coverage' do - subject { described_class.new :coverage => 99 } + subject { described_class.new coverage: 99 } it { is_expected.not_to succeed_with_output 'some dummy output with no coverage' } it { is_expected.not_to succeed_with_output '98.99999% documented' } diff --git a/spec/lib/fudge/tasks_spec.rb b/spec/lib/fudge/tasks_spec.rb index dc0b864..a1ebef9 100644 --- a/spec/lib/fudge/tasks_spec.rb +++ b/spec/lib/fudge/tasks_spec.rb @@ -7,11 +7,11 @@ def self.name end describe Fudge::Tasks do - describe "Class Methods" do + describe 'Class Methods' do subject { described_class } describe '#register' do - it "should register a task for a given symbol" do + it 'should register a task for a given symbol' do subject.register(TestTask) expect(subject.discover(:foo)).to eq(TestTask) @@ -19,13 +19,13 @@ def self.name end describe '#discover' do - it "should return the registered class for the given symbol" do + it 'should return the registered class for the given symbol' do subject.register(TestTask) expect(subject.discover(:foo)).to eq(TestTask) end - it "should raise an exception if the task is not found" do + it 'should raise an exception if the task is not found' do no_task_error = Fudge::Exceptions::TaskNotFound expect { subject.discover(:something) }.to raise_error no_task_error end diff --git a/spec/lib/fudge/with_directory_spec.rb b/spec/lib/fudge/with_directory_spec.rb index a051f9f..9805b9c 100644 --- a/spec/lib/fudge/with_directory_spec.rb +++ b/spec/lib/fudge/with_directory_spec.rb @@ -6,8 +6,8 @@ subject { described_class.new '/some/dir', formatter } - describe "#inside" do - it "outputs the directory change, yielding the block" do + describe '#inside' do + it 'outputs the directory change, yielding the block' do expect(Dir).to receive(:chdir).with('/some/dir').and_yield subject.inside do end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aedc4a6..5c7787d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require 'simplecov' SimpleCov.start do - add_filter "spec/" + add_filter 'spec/' end require 'rspec' diff --git a/spec/support/dummy_task.rb b/spec/support/dummy_task.rb index 6b846ed..8e6ed02 100644 --- a/spec/support/dummy_task.rb +++ b/spec/support/dummy_task.rb @@ -13,7 +13,7 @@ def initialize(*args) self.args = args end - def run(options={}) + def run(options = {}) self.class.ran = true self.class.run_options = options end From 360db7631ac81547f458ffd1d6a52d0be91b9f55 Mon Sep 17 00:00:00 2001 From: Stephen Lloyd-Hirst Date: Thu, 21 Apr 2016 12:15:08 +0100 Subject: [PATCH 2/4] More spec improvements --- Fudgefile | 2 +- spec/lib/fudge/build_spec.rb | 2 +- spec/lib/fudge/cli_spec.rb | 4 ++-- spec/lib/fudge/description_spec.rb | 5 ++++- spec/lib/fudge/tasks/task_spec.rb | 6 +++--- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Fudgefile b/Fudgefile index 1a2b92a..8d58000 100644 --- a/Fudgefile +++ b/Fudgefile @@ -15,7 +15,7 @@ task_group :duplication do end task_group :complexity do - task :flog, exclude: '^\.\/spec\/', max: 13, average: 4.1, methods: true + task :flog, exclude: '^\.\/spec\/', max: 11.6, average: 4.1, methods: true end task_group :shout_about_success do diff --git a/spec/lib/fudge/build_spec.rb b/spec/lib/fudge/build_spec.rb index f71525b..991598c 100644 --- a/spec/lib/fudge/build_spec.rb +++ b/spec/lib/fudge/build_spec.rb @@ -37,7 +37,7 @@ it 'should print out the time of the build' do expect(subject).to receive(:message) do |message| - expect(message).to match /Finished in \d+.\d\d seconds./ + expect(message).to match(/Finished in \d+.\d\d seconds./) end subject.run formatter: formatter end diff --git a/spec/lib/fudge/cli_spec.rb b/spec/lib/fudge/cli_spec.rb index 26d5281..4d7bd91 100644 --- a/spec/lib/fudge/cli_spec.rb +++ b/spec/lib/fudge/cli_spec.rb @@ -50,8 +50,8 @@ def run(_options = {}) end describe '.init' do - let (:file_state) { { exists: false, content: '' } } - let (:override_file_state) do + let(:file_state) { { exists: false, content: '' } } + let(:override_file_state) do lambda do |exists, content| file_state[:exists] = exists file_state[:content] = content diff --git a/spec/lib/fudge/description_spec.rb b/spec/lib/fudge/description_spec.rb index e227102..f4b6ab8 100644 --- a/spec/lib/fudge/description_spec.rb +++ b/spec/lib/fudge/description_spec.rb @@ -215,7 +215,10 @@ def make_build it 'fails the build HARD when hooks fail' do make_build do - subject.on_failure { subject.shell 'fail'; subject.shell 'FOO' } + subject.on_failure do + subject.shell 'fail' + subject.shell 'FOO' + end subject.on_failure { subject.shell 'BAR' } end diff --git a/spec/lib/fudge/tasks/task_spec.rb b/spec/lib/fudge/tasks/task_spec.rb index 62f8bc8..7145cab 100644 --- a/spec/lib/fudge/tasks/task_spec.rb +++ b/spec/lib/fudge/tasks/task_spec.rb @@ -24,7 +24,7 @@ class SomeTask < Fudge::Tasks::Task end context 'given options' do - let (:task) { MyTask.new cod: 'fanglers' } + let(:task) { MyTask.new cod: 'fanglers' } it 'accepts and sets the options' do expect(task.cod).to eq 'fanglers' @@ -35,7 +35,7 @@ class SomeTask < Fudge::Tasks::Task end context 'including an option that is not supported' do - let (:task) { MyTask.new cod: 'fanglers', foo: 'bar' } + let(:task) { MyTask.new cod: 'fanglers', foo: 'bar' } it 'ignores the unsupported options' do expect(task._methods_missing).to be_nil @@ -48,7 +48,7 @@ class SomeTask < Fudge::Tasks::Task end context 'given arguments and options' do - let (:task) { MyTask.new :foo, :bar, cod: 'fanglers' } + let(:task) { MyTask.new :foo, :bar, cod: 'fanglers' } it 'stores the arguments separately from the options' do expect(task.args).to match_array [:foo, :bar] From 0929763428a7e6e0ada1dc49b07bec79e576baf8 Mon Sep 17 00:00:00 2001 From: Stephen Lloyd-Hirst Date: Thu, 21 Apr 2016 13:17:51 +0100 Subject: [PATCH 3/4] Update build environments --- .travis.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b812d6..3a90550 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,12 @@ language: ruby rvm: - - 2.1.0 - - 2.1.1 - - 2.1.2 - - 2.0.0 - - 1.9.3 + - 2.3.0 + - 2.2.3 + - jruby-19mode + - jruby-9.0.5.0 + - rbx-2 + +matrix: + allow_failures: + - rvm: rbx-2 + - rvm: jruby-19mode From 54a3f32dde1c6e9c638ad66b008110146c254c2f Mon Sep 17 00:00:00 2001 From: Stephen Lloyd-Hirst Date: Thu, 21 Apr 2016 14:07:51 +0100 Subject: [PATCH 4/4] Remove jruby --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3a90550..a1a7d76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,8 @@ language: ruby rvm: - 2.3.0 - 2.2.3 - - jruby-19mode - - jruby-9.0.5.0 - rbx-2 matrix: allow_failures: - rvm: rbx-2 - - rvm: jruby-19mode