fudge 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/fudge/build.rb +25 -10
- data/lib/fudge/cli.rb +1 -0
- data/lib/fudge/rspec/matchers.rb +54 -49
- data/lib/fudge/runner.rb +1 -0
- data/lib/fudge/tasks/composite_task.rb +6 -4
- data/lib/fudge/tasks/each_directory.rb +1 -1
- data/lib/fudge/tasks/in_directory.rb +1 -1
- data/lib/fudge/tasks/shell.rb +1 -1
- data/lib/fudge/tasks/task.rb +5 -0
- data/lib/fudge/version.rb +1 -1
- data/spec/lib/fudge/build_spec.rb +19 -4
- data/spec/lib/fudge/cli_spec.rb +16 -16
- data/spec/lib/fudge/description_spec.rb +43 -42
- data/spec/lib/fudge/exceptions_spec.rb +17 -7
- data/spec/lib/fudge/formatters/simple_spec.rb +15 -15
- data/spec/lib/fudge/output_checker_spec.rb +2 -2
- data/spec/lib/fudge/parser_spec.rb +3 -3
- data/spec/lib/fudge/runner_spec.rb +9 -9
- data/spec/lib/fudge/tasks/brakeman_spec.rb +7 -7
- data/spec/lib/fudge/tasks/bundler_spec.rb +5 -5
- data/spec/lib/fudge/tasks/cane_spec.rb +8 -8
- data/spec/lib/fudge/tasks/composite_task_spec.rb +16 -15
- data/spec/lib/fudge/tasks/each_directory_spec.rb +9 -9
- data/spec/lib/fudge/tasks/flay_spec.rb +8 -8
- data/spec/lib/fudge/tasks/flog_spec.rb +13 -13
- data/spec/lib/fudge/tasks/in_directory_spec.rb +4 -4
- data/spec/lib/fudge/tasks/rake_spec.rb +5 -5
- data/spec/lib/fudge/tasks/rspec_spec.rb +16 -16
- data/spec/lib/fudge/tasks/shell_spec.rb +14 -14
- data/spec/lib/fudge/tasks/sub_process_spec.rb +3 -3
- data/spec/lib/fudge/tasks/task_spec.rb +1 -1
- data/spec/lib/fudge/tasks/yard_spec.rb +10 -10
- data/spec/lib/fudge/tasks_spec.rb +4 -4
- data/spec/lib/fudge/with_directory_spec.rb +2 -2
- metadata +145 -107
- checksums.yaml +0 -7
    
        data/lib/fudge/build.rb
    CHANGED
    
    | @@ -6,9 +6,10 @@ module Fudge | |
| 6 6 | 
             
                #   @return [String] a brief description of the build; this is
         | 
| 7 7 | 
             
                #                    output by the 'list' command
         | 
| 8 8 | 
             
                attr_accessor :about
         | 
| 9 | 
            -
                attr_accessor :callbacks
         | 
| 9 | 
            +
                attr_accessor :callbacks, :time
         | 
| 10 10 | 
             
                attr_reader :success_hooks, :failure_hooks
         | 
| 11 11 | 
             
                attr_reader :description
         | 
| 12 | 
            +
                attr_reader :formatter
         | 
| 12 13 |  | 
| 13 14 | 
             
                def initialize(*args)
         | 
| 14 15 | 
             
                  @success_hooks = []
         | 
| @@ -19,26 +20,40 @@ module Fudge | |
| 19 20 |  | 
| 20 21 | 
             
                # Run task
         | 
| 21 22 | 
             
                def run(options={})
         | 
| 22 | 
            -
                   | 
| 23 | 
            +
                  start_time = Time.new
         | 
| 24 | 
            +
                  init_formatter(options)
         | 
| 23 25 | 
             
                  success = super
         | 
| 24 26 | 
             
                  if callbacks
         | 
| 25 | 
            -
                     | 
| 26 | 
            -
                    hooks = success ? @success_hooks : @failure_hooks
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                    hooks.each do |hook|
         | 
| 29 | 
            -
                      return false unless hook.run :formatter => formatter
         | 
| 30 | 
            -
                    end
         | 
| 27 | 
            +
                    return false unless run_callbacks(success)
         | 
| 31 28 | 
             
                  else
         | 
| 32 | 
            -
                    message "Skipping callbacks..." | 
| 29 | 
            +
                    message "Skipping callbacks..."
         | 
| 33 30 | 
             
                  end
         | 
| 31 | 
            +
                  report_time(start_time, time)
         | 
| 34 32 |  | 
| 35 33 | 
             
                  success
         | 
| 36 34 | 
             
                end
         | 
| 37 35 |  | 
| 38 36 | 
             
                private
         | 
| 39 37 |  | 
| 40 | 
            -
                def message(message | 
| 38 | 
            +
                def message(message)
         | 
| 41 39 | 
             
                  formatter.write { |w| w.info(message) }
         | 
| 42 40 | 
             
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def init_formatter(options)
         | 
| 43 | 
            +
                  @formatter = options[:formatter] || Fudge::Formatters::Simple.new
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                def report_time(start_time, time)
         | 
| 47 | 
            +
                  message "Finished in #{"%.2f" % (Time.new - start_time)} seconds." if time
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                def run_callbacks(success)
         | 
| 51 | 
            +
                  message "Running #{success ? 'success' : 'failure'} callbacks..."
         | 
| 52 | 
            +
                  hooks = success ? @success_hooks : @failure_hooks
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  hooks.each do |hook|
         | 
| 55 | 
            +
                    return false unless hook.run :formatter => formatter
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
                end
         | 
| 43 58 | 
             
              end
         | 
| 44 59 | 
             
            end
         | 
    
        data/lib/fudge/cli.rb
    CHANGED
    
    | @@ -14,6 +14,7 @@ module Fudge | |
| 14 14 | 
             
                desc "build [BUILD_NAME]",
         | 
| 15 15 | 
             
                  "Run a build with the given name (default: 'default')"
         | 
| 16 16 | 
             
                method_option :callbacks, :type => :boolean, :default => false
         | 
| 17 | 
            +
                method_option :time, :type => :boolean, :default => false
         | 
| 17 18 | 
             
                # Runs the parsed builds
         | 
| 18 19 | 
             
                # @param [String] build_name the given build to run (default 'default')
         | 
| 19 20 | 
             
                def build(build_name='default')
         | 
    
        data/lib/fudge/rspec/matchers.rb
    CHANGED
    
    | @@ -4,68 +4,65 @@ RSpec::Matchers.define :be_registered_as do |key| | |
| 4 4 | 
             
              end
         | 
| 5 5 | 
             
            end
         | 
| 6 6 |  | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
                 | 
| 7 | 
            +
            RSpec::Matchers.define :run_command do |*expected|
         | 
| 8 | 
            +
              match do |actual|
         | 
| 9 | 
            +
                @args = expected.last.kind_of?(Hash) ? expected.delete_at(-1) : {}
         | 
| 10 | 
            +
                @commands = expected
         | 
| 11 | 
            +
                @args[:formatter] ||= Fudge::Formatters::Simple.new
         | 
| 12 12 |  | 
| 13 | 
            -
                 | 
| 14 | 
            -
                  @expected = expected
         | 
| 15 | 
            -
                  @args = args
         | 
| 16 | 
            -
                  @args[:formatter] ||= Fudge::Formatters::Simple.new
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                def matches?(task)
         | 
| 20 | 
            -
                  @task = task
         | 
| 21 | 
            -
                  ran = []
         | 
| 13 | 
            +
                @ran = []
         | 
| 22 14 |  | 
| 23 | 
            -
             | 
| 24 | 
            -
                    if task.is_a?(Fudge::Tasks::Shell)
         | 
| 25 | 
            -
                      task
         | 
| 26 | 
            -
                    else
         | 
| 27 | 
            -
                      Fudge::Tasks::Shell.any_instance
         | 
| 28 | 
            -
                    end
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                  to_stub.stub(:run_command) do |cmd, formatter|
         | 
| 15 | 
            +
                stub = ->(*cmd, formatter) {
         | 
| 31 16 | 
             
                    raise "Run Command requires a formatter" unless formatter
         | 
| 32 | 
            -
                    ran.push(cmd)
         | 
| 17 | 
            +
                    @ran.push(*cmd)
         | 
| 33 18 | 
             
                    ['dummy output', true]
         | 
| 34 | 
            -
             | 
| 19 | 
            +
                }
         | 
| 35 20 |  | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
                   | 
| 21 | 
            +
                if RSpec::Version::STRING =~ /\A3\.[0-9]+\.[0-9]+/
         | 
| 22 | 
            +
                  if actual.is_a?(Fudge::Tasks::Shell)
         | 
| 23 | 
            +
                    allow(actual).to receive(:run_command, &stub)
         | 
| 24 | 
            +
                  else
         | 
| 25 | 
            +
                    allow_any_instance_of(Fudge::Tasks::Shell).to receive(:run_command, &stub)
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
                else
         | 
| 28 | 
            +
                  if actual.is_a?(Fudge::Tasks::Shell)
         | 
| 29 | 
            +
                    actual.stub(:run_command, &stub)
         | 
| 30 | 
            +
                  else
         | 
| 31 | 
            +
                    Fudge::Tasks::Shell.any_instance.stub(:run_command, &stub)
         | 
| 32 | 
            +
                  end
         | 
| 40 33 | 
             
                end
         | 
| 41 34 |  | 
| 42 | 
            -
                 | 
| 43 | 
            -
                def failure_message_for_should
         | 
| 44 | 
            -
                  message = ""
         | 
| 45 | 
            -
                  message << "Expected task :#{@task.class.name} "
         | 
| 46 | 
            -
                  message << "to run:\n  #{@expected}\n"
         | 
| 47 | 
            -
                  message << "but it ran:\n  #{@actual}"
         | 
| 48 | 
            -
                end
         | 
| 35 | 
            +
                actual.run(@args)
         | 
| 49 36 |  | 
| 50 | 
            -
                 | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
                    ran.any? {|cmd| cmd =~ expected}
         | 
| 37 | 
            +
                @commands.all? do |cmd|
         | 
| 38 | 
            +
                  if cmd.is_a? Regexp
         | 
| 39 | 
            +
                    @ran.any? {|ran| ran =~ cmd}
         | 
| 54 40 | 
             
                  else
         | 
| 55 | 
            -
                    ran.include?  | 
| 41 | 
            +
                    @ran.include? cmd
         | 
| 56 42 | 
             
                  end
         | 
| 57 43 | 
             
                end
         | 
| 58 44 | 
             
              end
         | 
| 59 | 
            -
            end
         | 
| 60 45 |  | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 46 | 
            +
              format_message = ->(actual) {
         | 
| 47 | 
            +
                message = ""
         | 
| 48 | 
            +
                message << "Expected task :#{actual.class.name} "
         | 
| 49 | 
            +
                message << "to run:\n  #{@commands}\n"
         | 
| 50 | 
            +
                message << "but it ran:\n  #{@ran}"
         | 
| 51 | 
            +
              }
         | 
| 52 | 
            +
              if RSpec::Version::STRING =~ /\A3\.[0-9]+\.[0-9]+/
         | 
| 53 | 
            +
                failure_message(&format_message)
         | 
| 54 | 
            +
              else
         | 
| 55 | 
            +
                failure_message_for_should(&format_message)
         | 
| 56 | 
            +
              end
         | 
| 64 57 | 
             
            end
         | 
| 65 58 |  | 
| 66 59 | 
             
            RSpec::Matchers.define :succeed_with_output do |output|
         | 
| 67 60 | 
             
              match do |subject|
         | 
| 68 | 
            -
                 | 
| 61 | 
            +
                if RSpec::Version::STRING =~ /\A3\.[0-9]+\.[0-9]+/
         | 
| 62 | 
            +
                  allow(subject).to receive(:run_command).and_return([output, true])
         | 
| 63 | 
            +
                else
         | 
| 64 | 
            +
                  subject.stub(:run_command).and_return([output, true])
         | 
| 65 | 
            +
                end
         | 
| 69 66 |  | 
| 70 67 | 
             
                subject.run
         | 
| 71 68 | 
             
              end
         | 
| @@ -76,11 +73,19 @@ shared_examples_for 'bundle aware' do | |
| 76 73 | 
             
                @normal_cmd = subject.send(:cmd)
         | 
| 77 74 | 
             
              end
         | 
| 78 75 |  | 
| 79 | 
            -
              it " | 
| 80 | 
            -
                 | 
| 76 | 
            +
              it "prefixes the command with bundle exec when bundler is set" do
         | 
| 77 | 
            +
                if RSpec::Version::STRING =~ /\A3\.[0-9]+\.[0-9]+/
         | 
| 78 | 
            +
                  expect(subject).to run_command("bundle exec #{@normal_cmd}", :bundler => true)
         | 
| 79 | 
            +
                else
         | 
| 80 | 
            +
                  subject.should run_command("bundle exec #{@normal_cmd}", :bundler => true)
         | 
| 81 | 
            +
                end
         | 
| 81 82 | 
             
              end
         | 
| 82 83 |  | 
| 83 | 
            -
              it " | 
| 84 | 
            -
                 | 
| 84 | 
            +
              it "does not prefix the command with bundle exec when bundler is not set" do
         | 
| 85 | 
            +
                if RSpec::Version::STRING =~ /\A3\.[0-9]+\.[0-9]+/
         | 
| 86 | 
            +
                  expect(subject).to run_command(@normal_cmd, :bundler => false)
         | 
| 87 | 
            +
                else
         | 
| 88 | 
            +
                  subject.should run_command(@normal_cmd, :bundler => false)
         | 
| 89 | 
            +
                end
         | 
| 85 90 | 
             
              end
         | 
| 86 91 | 
             
            end
         | 
    
        data/lib/fudge/runner.rb
    CHANGED
    
    
| @@ -13,7 +13,7 @@ module Fudge | |
| 13 13 |  | 
| 14 14 | 
             
                  # Runs the task (by default running all other tasks in order)
         | 
| 15 15 | 
             
                  def run(options={})
         | 
| 16 | 
            -
                    formatter = options | 
| 16 | 
            +
                    formatter = get_formatter(options)
         | 
| 17 17 | 
             
                    tasks.each do |t|
         | 
| 18 18 | 
             
                      apply_directory_settings(t)
         | 
| 19 19 | 
             
                      output_message(t, formatter)
         | 
| @@ -53,9 +53,11 @@ module Fudge | |
| 53 53 | 
             
                  end
         | 
| 54 54 |  | 
| 55 55 | 
             
                  def output_message(t, formatter)
         | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 56 | 
            +
                    name = task_name(t)
         | 
| 57 | 
            +
                    args = args_s(t)
         | 
| 58 | 
            +
                    formatter.write do |w|
         | 
| 59 | 
            +
                      w.info("Running task").notice(name).notice(args)
         | 
| 60 | 
            +
                    end
         | 
| 59 61 | 
             
                  end
         | 
| 60 62 |  | 
| 61 63 | 
             
                end
         | 
| @@ -13,7 +13,7 @@ module Fudge | |
| 13 13 |  | 
| 14 14 | 
             
                  # Run task
         | 
| 15 15 | 
             
                  def run(options={})
         | 
| 16 | 
            -
                    formatter = options | 
| 16 | 
            +
                    formatter = get_formatter(options)
         | 
| 17 17 | 
             
                    directories.all? do |dir|
         | 
| 18 18 | 
             
                      skip_directory?(dir) ||
         | 
| 19 19 | 
             
                        WithDirectory.new(dir, formatter).inside do
         | 
    
        data/lib/fudge/tasks/shell.rb
    CHANGED
    
    | @@ -12,7 +12,7 @@ module Fudge | |
| 12 12 | 
             
                  #
         | 
| 13 13 | 
             
                  # @param [Hash] options Any options to pass to the shell
         | 
| 14 14 | 
             
                  def run(options={})
         | 
| 15 | 
            -
                    formatter = options | 
| 15 | 
            +
                    formatter = get_formatter(options)
         | 
| 16 16 | 
             
                    @output, success = run_command(cmd(options), formatter)
         | 
| 17 17 |  | 
| 18 18 | 
             
                    return false unless success
         | 
    
        data/lib/fudge/tasks/task.rb
    CHANGED
    
    
    
        data/lib/fudge/version.rb
    CHANGED
    
    
| @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe Fudge::Build do
         | 
| 4 | 
            -
              it {  | 
| 4 | 
            +
              it { is_expected.to be_a Fudge::Tasks::CompositeTask }
         | 
| 5 5 |  | 
| 6 6 | 
             
              describe "#run" do
         | 
| 7 7 |  | 
| @@ -12,8 +12,8 @@ describe Fudge::Build do | |
| 12 12 | 
             
                  it "prints messages to the formatter instead of default" do
         | 
| 13 13 | 
             
                    subject.run :formatter => formatter
         | 
| 14 14 |  | 
| 15 | 
            -
                    stdout.string. | 
| 16 | 
            -
                    stdout.string. | 
| 15 | 
            +
                    expect(stdout.string).not_to be_empty
         | 
| 16 | 
            +
                    expect(stdout.string).to include "Skipping callbacks..."
         | 
| 17 17 | 
             
                  end
         | 
| 18 18 |  | 
| 19 19 | 
             
                  context "when there are callback hooks" do
         | 
| @@ -25,7 +25,22 @@ describe Fudge::Build do | |
| 25 25 | 
             
                    end
         | 
| 26 26 |  | 
| 27 27 | 
             
                    it "passesformatter down to the hook run" do
         | 
| 28 | 
            -
                      hook. | 
| 28 | 
            +
                      expect(hook).to receive(:run).with(:formatter =>formatter).and_return(true)
         | 
| 29 | 
            +
                      subject.run :formatter => formatter
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  context "when the `time` flag is set" do
         | 
| 34 | 
            +
                    before do
         | 
| 35 | 
            +
                      subject.callbacks = true
         | 
| 36 | 
            +
                      allow(subject).to receive(:run_callbacks).and_return(true)
         | 
| 37 | 
            +
                      subject.time = true
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    it "should print out the time of the build" do
         | 
| 41 | 
            +
                      expect(subject).to receive(:message) do |message|
         | 
| 42 | 
            +
                        expect(message).to match /Finished in \d+.\d\d seconds./
         | 
| 43 | 
            +
                      end
         | 
| 29 44 | 
             
                      subject.run :formatter => formatter
         | 
| 30 45 | 
             
                    end
         | 
| 31 46 | 
             
                  end
         | 
    
        data/spec/lib/fudge/cli_spec.rb
    CHANGED
    
    | @@ -18,7 +18,7 @@ describe Fudge::Cli do | |
| 18 18 | 
             
                AnotherDummyTask.ran = false
         | 
| 19 19 | 
             
              end
         | 
| 20 20 |  | 
| 21 | 
            -
              describe  | 
| 21 | 
            +
              describe ".build" do
         | 
| 22 22 | 
             
                before :each do
         | 
| 23 23 | 
             
                  contents = <<-RUBY
         | 
| 24 24 | 
             
                      build :default do
         | 
| @@ -30,26 +30,26 @@ describe Fudge::Cli do | |
| 30 30 | 
             
                      end
         | 
| 31 31 | 
             
                    RUBY
         | 
| 32 32 | 
             
                  file = double(File, read: contents, path: 'here')
         | 
| 33 | 
            -
                  File. | 
| 33 | 
            +
                  allow(File).to receive(:open) { |&block| block.yield file }
         | 
| 34 34 | 
             
                end
         | 
| 35 35 |  | 
| 36 36 | 
             
                context "when not given a build name" do
         | 
| 37 37 | 
             
                  it "runs the default build" do
         | 
| 38 38 | 
             
                    subject.build 'default'
         | 
| 39 | 
            -
                    expect(DummyTask.ran).to  | 
| 39 | 
            +
                    expect(DummyTask.ran).to be_truthy
         | 
| 40 40 | 
             
                  end
         | 
| 41 41 | 
             
                end
         | 
| 42 42 |  | 
| 43 43 | 
             
                context "when given a build name" do
         | 
| 44 44 | 
             
                  it "runs the only the named build" do
         | 
| 45 45 | 
             
                    subject.build 'other'
         | 
| 46 | 
            -
                    expect(DummyTask.ran).to  | 
| 47 | 
            -
                    expect(AnotherDummyTask.ran).to  | 
| 46 | 
            +
                    expect(DummyTask.ran).to be_falsey
         | 
| 47 | 
            +
                    expect(AnotherDummyTask.ran).to be_truthy
         | 
| 48 48 | 
             
                  end
         | 
| 49 49 | 
             
                end
         | 
| 50 50 | 
             
              end
         | 
| 51 51 |  | 
| 52 | 
            -
              describe  | 
| 52 | 
            +
              describe ".init" do
         | 
| 53 53 | 
             
                let (:file_state) { { exists: false, content: '' } }
         | 
| 54 54 | 
             
                let (:override_file_state) do
         | 
| 55 55 | 
             
                  ->(exists, content) {
         | 
| @@ -60,18 +60,18 @@ describe Fudge::Cli do | |
| 60 60 |  | 
| 61 61 | 
             
                before :each do
         | 
| 62 62 | 
             
                  file = double(File)
         | 
| 63 | 
            -
                  file. | 
| 64 | 
            -
                  file. | 
| 65 | 
            -
                  File. | 
| 63 | 
            +
                  allow(file).to receive(:<<) { |str| file_state[:content] = str }
         | 
| 64 | 
            +
                  allow(file).to receive(:read) { file_state[:content] }
         | 
| 65 | 
            +
                  allow(File).to receive(:open) do |&block|
         | 
| 66 66 | 
             
                    file_state[:exists] = true
         | 
| 67 67 | 
             
                    block.yield file
         | 
| 68 68 | 
             
                  end
         | 
| 69 | 
            -
                  File. | 
| 69 | 
            +
                  allow(File).to receive(:exists?) { |_| file_state[:exists] }
         | 
| 70 70 |  | 
| 71 71 | 
             
                  @output = ''
         | 
| 72 72 | 
             
                  shell = double('Thor::Shell')
         | 
| 73 | 
            -
                  shell. | 
| 74 | 
            -
                  subject. | 
| 73 | 
            +
                  allow(shell).to receive(:say) { |what| @output = what }
         | 
| 74 | 
            +
                  allow(subject).to receive(:shell).and_return(shell)
         | 
| 75 75 | 
             
                end
         | 
| 76 76 |  | 
| 77 77 | 
             
                context "when a Fudgefile does not exist in the current directory" do
         | 
| @@ -117,7 +117,7 @@ describe Fudge::Cli do | |
| 117 117 | 
             
                end
         | 
| 118 118 | 
             
              end
         | 
| 119 119 |  | 
| 120 | 
            -
              describe  | 
| 120 | 
            +
              describe ".list" do
         | 
| 121 121 | 
             
                before :each do
         | 
| 122 122 | 
             
                  contents = <<-RUBY
         | 
| 123 123 | 
             
                      build :default do
         | 
| @@ -129,12 +129,12 @@ describe Fudge::Cli do | |
| 129 129 | 
             
                      end
         | 
| 130 130 | 
             
                    RUBY
         | 
| 131 131 | 
             
                  file = double(File, read: contents, path: 'here')
         | 
| 132 | 
            -
                  File. | 
| 132 | 
            +
                  allow(File).to receive(:open) { |&block| block.yield file }
         | 
| 133 133 |  | 
| 134 134 | 
             
                  @output = ''
         | 
| 135 135 | 
             
                  shell = double('Thor::Shell')
         | 
| 136 | 
            -
                  shell. | 
| 137 | 
            -
                  subject. | 
| 136 | 
            +
                  allow(shell).to receive(:print_table) { |tab| @output = tab.map { |build, desc| "#{build}\t#{desc}" }.join("\n") }
         | 
| 137 | 
            +
                  allow(subject).to receive(:shell).and_return(shell)
         | 
| 138 138 | 
             
                end
         | 
| 139 139 |  | 
| 140 140 | 
             
                context "when not given a filter string" do
         | 
| @@ -1,8 +1,13 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe Fudge::Description do
         | 
| 4 | 
            +
              let(:input) { '' }
         | 
| 5 | 
            +
              let(:file) { StringIO.new(input).tap { |s| allow(s).to receive(:path).and_return('') } }
         | 
| 6 | 
            +
              subject { described_class.new(file) }
         | 
| 7 | 
            +
             | 
| 4 8 | 
             
              let(:build) { subject.builds.values.first }
         | 
| 5 | 
            -
              let(:build_tasks) { build.tasks. | 
| 9 | 
            +
              let(:build_tasks) { build.tasks.dup }
         | 
| 10 | 
            +
             | 
| 6 11 |  | 
| 7 12 | 
             
              def make_build
         | 
| 8 13 | 
             
                subject.build :default do
         | 
| @@ -12,38 +17,34 @@ describe Fudge::Description do | |
| 12 17 | 
             
                build.callbacks = callbacks
         | 
| 13 18 | 
             
              end
         | 
| 14 19 |  | 
| 15 | 
            -
               | 
| 16 | 
            -
              let(:file) { StringIO.new(input).tap { |s| s.stub(:path).and_return('') } }
         | 
| 17 | 
            -
              subject { described_class.new file }
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              describe :initialize do
         | 
| 20 | 
            +
              describe "#initialize" do
         | 
| 20 21 | 
             
                let(:input) { 'build :foo do; end' }
         | 
| 21 22 |  | 
| 22 23 | 
             
                it "should add the builds in the given string" do
         | 
| 23 | 
            -
                  subject.builds[:foo]. | 
| 24 | 
            +
                  expect(subject.builds[:foo]).to be_a Fudge::Build
         | 
| 24 25 | 
             
                end
         | 
| 25 26 | 
             
              end
         | 
| 26 27 |  | 
| 27 | 
            -
              describe  | 
| 28 | 
            +
              describe "#build" do
         | 
| 28 29 | 
             
                it "should create a new build and add it to the builds array" do
         | 
| 29 | 
            -
                  subject.builds. | 
| 30 | 
            +
                  expect(subject.builds).to be_empty
         | 
| 30 31 |  | 
| 31 32 | 
             
                  subject.build :some_branch do
         | 
| 32 33 | 
             
                  end
         | 
| 33 34 |  | 
| 34 | 
            -
                  subject.builds. | 
| 35 | 
            -
                  subject.builds[:some_branch]. | 
| 35 | 
            +
                  expect(subject.builds.size).to eq(1)
         | 
| 36 | 
            +
                  expect(subject.builds[:some_branch]).to be_a Fudge::Build
         | 
| 36 37 | 
             
                end
         | 
| 37 38 | 
             
              end
         | 
| 38 39 |  | 
| 39 | 
            -
              describe  | 
| 40 | 
            +
              describe "#task" do
         | 
| 40 41 | 
             
                it "should add a task to the current scope" do
         | 
| 41 42 | 
             
                  subject.build :default do
         | 
| 42 43 | 
             
                    subject.task :dummy
         | 
| 43 44 | 
             
                  end
         | 
| 44 45 |  | 
| 45 | 
            -
                  build_tasks. | 
| 46 | 
            -
                  build_tasks.first. | 
| 46 | 
            +
                  expect(build_tasks.size).to eq(1)
         | 
| 47 | 
            +
                  expect(build_tasks.first).to be_a DummyTask
         | 
| 47 48 | 
             
                end
         | 
| 48 49 |  | 
| 49 50 | 
             
                it "should pass arguments to the initializer" do
         | 
| @@ -51,7 +52,7 @@ describe Fudge::Description do | |
| 51 52 | 
             
                    subject.task :dummy, :foo, :bar
         | 
| 52 53 | 
             
                  end
         | 
| 53 54 |  | 
| 54 | 
            -
                  build_tasks.first.args. | 
| 55 | 
            +
                  expect(build_tasks.first.args).to eq([:foo, :bar])
         | 
| 55 56 | 
             
                end
         | 
| 56 57 |  | 
| 57 58 | 
             
                it "should forward missing methods to task" do
         | 
| @@ -59,7 +60,7 @@ describe Fudge::Description do | |
| 59 60 | 
             
                    subject.dummy :foo, :bar
         | 
| 60 61 | 
             
                  end
         | 
| 61 62 |  | 
| 62 | 
            -
                  build_tasks.first.args. | 
| 63 | 
            +
                  expect(build_tasks.first.args).to eq([:foo, :bar])
         | 
| 63 64 | 
             
                end
         | 
| 64 65 |  | 
| 65 66 | 
             
                it "should super method_missing if no task found" do
         | 
| @@ -73,11 +74,11 @@ describe Fudge::Description do | |
| 73 74 | 
             
                    end
         | 
| 74 75 | 
             
                  end
         | 
| 75 76 |  | 
| 76 | 
            -
                  build_tasks.first.tasks.first. | 
| 77 | 
            +
                  expect(build_tasks.first.tasks.first).to be_a DummyTask
         | 
| 77 78 | 
             
                end
         | 
| 78 79 | 
             
              end
         | 
| 79 80 |  | 
| 80 | 
            -
              describe  | 
| 81 | 
            +
              describe "#task_group" do
         | 
| 81 82 | 
             
                it "should add a task group and allow it to be used in a build" do
         | 
| 82 83 | 
             
                  subject.task_group :group1 do
         | 
| 83 84 | 
             
                    subject.task :dummy
         | 
| @@ -88,7 +89,7 @@ describe Fudge::Description do | |
| 88 89 | 
             
                  end
         | 
| 89 90 |  | 
| 90 91 | 
             
                  subject.builds[:default].run
         | 
| 91 | 
            -
                  DummyTask.ran. | 
| 92 | 
            +
                  expect(DummyTask.ran).to be_truthy
         | 
| 92 93 | 
             
                end
         | 
| 93 94 |  | 
| 94 95 | 
             
                it "should allow passing arguments to task groups" do
         | 
| @@ -101,7 +102,7 @@ describe Fudge::Description do | |
| 101 102 | 
             
                  end
         | 
| 102 103 |  | 
| 103 104 | 
             
                  subject.builds[:default].run
         | 
| 104 | 
            -
                  DummyTask.ran. | 
| 105 | 
            +
                  expect(DummyTask.ran).to be_truthy
         | 
| 105 106 | 
             
                end
         | 
| 106 107 |  | 
| 107 108 | 
             
                it "should raise an exception if task group not found" do
         | 
| @@ -127,7 +128,7 @@ describe Fudge::Description do | |
| 127 128 | 
             
                    end
         | 
| 128 129 |  | 
| 129 130 | 
             
                    subject.builds[:default].run
         | 
| 130 | 
            -
                    DummyTask.ran. | 
| 131 | 
            +
                    expect(DummyTask.ran).to be_truthy
         | 
| 131 132 | 
             
                  end
         | 
| 132 133 |  | 
| 133 134 | 
             
                  it "supports when options are given" do
         | 
| @@ -140,9 +141,9 @@ describe Fudge::Description do | |
| 140 141 | 
             
                    subject.builds[:default].run
         | 
| 141 142 |  | 
| 142 143 | 
             
                    # Check that the options are maintained through the call
         | 
| 143 | 
            -
                    build_tasks.first.args. | 
| 144 | 
            -
                    build_tasks.first.args[1][:foobar]. | 
| 145 | 
            -
                    DummyTask.ran. | 
| 144 | 
            +
                    expect(build_tasks.first.args.size).to eq(2)
         | 
| 145 | 
            +
                    expect(build_tasks.first.args[1][:foobar]).to be_truthy
         | 
| 146 | 
            +
                    expect(DummyTask.ran).to be_truthy
         | 
| 146 147 | 
             
                  end
         | 
| 147 148 | 
             
                end
         | 
| 148 149 |  | 
| @@ -151,13 +152,13 @@ describe Fudge::Description do | |
| 151 152 | 
             
              describe "Callback Hooks" do
         | 
| 152 153 | 
             
                before :each do
         | 
| 153 154 | 
             
                  @ran = []
         | 
| 154 | 
            -
                  Fudge::Tasks::Shell. | 
| 155 | 
            -
                    @ran << cmd
         | 
| 156 | 
            -
                    ['', cmd != 'fail']
         | 
| 155 | 
            +
                  allow_any_instance_of(Fudge::Tasks::Shell).to receive(:run_command) do |cmd|
         | 
| 156 | 
            +
                    @ran << cmd.arguments
         | 
| 157 | 
            +
                    ['', cmd.arguments != 'fail']
         | 
| 157 158 | 
             
                  end
         | 
| 158 159 | 
             
                end
         | 
| 159 160 |  | 
| 160 | 
            -
                describe  | 
| 161 | 
            +
                describe "#on_success" do
         | 
| 161 162 | 
             
                  context "when callbacks is set to true" do
         | 
| 162 163 | 
             
                    let(:callbacks) { true }
         | 
| 163 164 |  | 
| @@ -167,8 +168,8 @@ describe Fudge::Description do | |
| 167 168 | 
             
                        subject.on_success { subject.shell 'BAR' }
         | 
| 168 169 | 
             
                      end
         | 
| 169 170 |  | 
| 170 | 
            -
                      build.run. | 
| 171 | 
            -
                      @ran. | 
| 171 | 
            +
                      expect(build.run).to be_truthy
         | 
| 172 | 
            +
                      expect(@ran).to eq(['FOO', 'BAR'])
         | 
| 172 173 | 
             
                    end
         | 
| 173 174 |  | 
| 174 175 | 
             
                    it "fails the build HARD when hooks fail" do
         | 
| @@ -177,8 +178,8 @@ describe Fudge::Description do | |
| 177 178 | 
             
                        subject.on_success { subject.shell 'BAR' }
         | 
| 178 179 | 
             
                      end
         | 
| 179 180 |  | 
| 180 | 
            -
                      build.run. | 
| 181 | 
            -
                      @ran. | 
| 181 | 
            +
                      expect(build.run).to be_falsey
         | 
| 182 | 
            +
                      expect(@ran).to eq(['fail'])
         | 
| 182 183 | 
             
                    end
         | 
| 183 184 | 
             
                  end
         | 
| 184 185 |  | 
| @@ -190,15 +191,15 @@ describe Fudge::Description do | |
| 190 191 | 
             
                        subject.on_success { subject.shell 'echo "WOOP"' }
         | 
| 191 192 | 
             
                      end
         | 
| 192 193 |  | 
| 193 | 
            -
                      build.run. | 
| 194 | 
            -
                      @ran. | 
| 194 | 
            +
                      expect(build.run).to be_truthy
         | 
| 195 | 
            +
                      expect(@ran).to eq([])
         | 
| 195 196 | 
             
                    end
         | 
| 196 197 | 
             
                  end
         | 
| 197 198 | 
             
                end
         | 
| 198 199 |  | 
| 199 | 
            -
                describe  | 
| 200 | 
            +
                describe "#on_failure" do
         | 
| 200 201 | 
             
                  before :each do
         | 
| 201 | 
            -
                    DummyTask. | 
| 202 | 
            +
                    allow_any_instance_of(DummyTask).to receive(:run).and_return(false)
         | 
| 202 203 | 
             
                  end
         | 
| 203 204 |  | 
| 204 205 | 
             
                  context "when callbacks is set to true" do
         | 
| @@ -210,8 +211,8 @@ describe Fudge::Description do | |
| 210 211 | 
             
                        subject.on_failure { subject.shell 'BAR' }
         | 
| 211 212 | 
             
                      end
         | 
| 212 213 |  | 
| 213 | 
            -
                      build.run. | 
| 214 | 
            -
                      @ran. | 
| 214 | 
            +
                      expect(build.run).to be_falsey
         | 
| 215 | 
            +
                      expect(@ran).to eq(['WOOP', 'BAR'])
         | 
| 215 216 | 
             
                    end
         | 
| 216 217 |  | 
| 217 218 | 
             
                    it "fails the build HARD when hooks fail" do
         | 
| @@ -220,8 +221,8 @@ describe Fudge::Description do | |
| 220 221 | 
             
                        subject.on_failure { subject.shell 'BAR' }
         | 
| 221 222 | 
             
                      end
         | 
| 222 223 |  | 
| 223 | 
            -
                      build.run. | 
| 224 | 
            -
                      @ran. | 
| 224 | 
            +
                      expect(build.run).to be_falsey
         | 
| 225 | 
            +
                      expect(@ran).to eq(['fail'])
         | 
| 225 226 | 
             
                    end
         | 
| 226 227 | 
             
                  end
         | 
| 227 228 |  | 
| @@ -233,8 +234,8 @@ describe Fudge::Description do | |
| 233 234 | 
             
                        subject.on_failure { subject.shell 'WOOP' }
         | 
| 234 235 | 
             
                      end
         | 
| 235 236 |  | 
| 236 | 
            -
                      build.run. | 
| 237 | 
            -
                      @ran. | 
| 237 | 
            +
                      expect(build.run).to be_falsey
         | 
| 238 | 
            +
                      expect(@ran).to eq([])
         | 
| 238 239 | 
             
                    end
         | 
| 239 240 | 
             
                  end
         | 
| 240 241 | 
             
                end
         |