fudge 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/fudge.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rainbow'
2
2
  require 'active_support/all'
3
3
 
4
+ # Fudge implementation
4
5
  module Fudge
5
6
  autoload :Build, 'fudge/build'
6
7
  autoload :Cli, 'fudge/cli'
data/lib/fudge/build.rb CHANGED
@@ -15,17 +15,23 @@ module Fudge
15
15
  def run(options={})
16
16
  success = super
17
17
  if callbacks
18
- puts "Running #{success ? 'success' : 'failure'} callbacks...".foreground(:cyan).bright
18
+ message "Running #{success ? 'success' : 'failure'} callbacks..."
19
19
  hooks = success ? @success_hooks : @failure_hooks
20
20
 
21
21
  hooks.each do |hook|
22
22
  return false unless hook.run
23
23
  end
24
24
  else
25
- puts "Skipping callbacks...".foreground(:cyan).bright
25
+ message "Skipping callbacks..."
26
26
  end
27
27
 
28
28
  success
29
29
  end
30
+
31
+ private
32
+
33
+ def message(message)
34
+ puts message.foreground(:cyan).bright
35
+ end
30
36
  end
31
37
  end
data/lib/fudge/cli.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require 'thor'
2
2
 
3
3
  module Fudge
4
+ # Fudge command line interface
4
5
  class Cli < Thor
5
6
  desc "init", "Initialize a blank Fudgefile"
7
+ # Initalizes the blank Fudgefile
6
8
  def init
7
9
  path = File.expand_path('Fudgefile', Dir.pwd)
8
10
 
@@ -19,8 +21,11 @@ RUBY
19
21
  end
20
22
  end
21
23
 
22
- desc "build [BUILD_NAME]", "Run a build with the given name (default: 'default')"
24
+ desc "build [BUILD_NAME]",
25
+ "Run a build with the given name (default: 'default')"
23
26
  method_option :callbacks, :type => :boolean, :default => false
27
+ # Runs the parsed builds
28
+ # @param [String] build_name the given build to run (default 'default')
24
29
  def build(build_name='default')
25
30
  description = Fudge::Parser.new.parse('Fudgefile')
26
31
  Fudge::Runner.new(description).run_build(build_name, options)
@@ -36,6 +36,7 @@ module Fudge
36
36
  end
37
37
  end
38
38
 
39
+ # Add actions to be invoked upon success
39
40
  def on_success
40
41
  task = Fudge::Tasks::CompositeTask.new
41
42
  current_scope.success_hooks << task
@@ -43,6 +44,7 @@ module Fudge
43
44
  with_scope(task) { yield }
44
45
  end
45
46
 
47
+ # Add actions to be invoked upon failure
46
48
  def on_failure
47
49
  task = Fudge::Tasks::CompositeTask.new
48
50
  current_scope.failure_hooks << task
@@ -1,28 +1,36 @@
1
1
  module Fudge
2
+ # Errors encountered
2
3
  module Exceptions
4
+ # Base class for failures
3
5
  class Base < StandardError; end
4
6
 
7
+ # Build failure error class
5
8
  class BuildFailed < Base
9
+ # error message
6
10
  def message
7
11
  "Build FAILED!".foreground(:red).bright
8
12
  end
9
13
  end
10
14
 
15
+ # Unknown task error class
11
16
  class TaskNotFound < Base
12
17
  def initialize(task)
13
18
  @task = task
14
19
  end
15
20
 
21
+ # error message
16
22
  def message
17
23
  "No task found with name '#{@task}'"
18
24
  end
19
25
  end
20
26
 
27
+ # Unknown task group error class
21
28
  class TaskGroupNotFound < Base
22
29
  def initialize(name)
23
30
  @name = name
24
31
  end
25
32
 
33
+ # error message
26
34
  def message
27
35
  "No task group found with name '#{@name}'"
28
36
  end
data/lib/fudge/helpers.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module Fudge
2
+ # Helper classes
2
3
  module Helpers
3
4
  require 'fudge/helpers/bundle_aware'
4
5
  end
@@ -1,5 +1,6 @@
1
1
  module Fudge
2
2
  module Helpers
3
+ # Work with Bundler
3
4
  module BundleAware
4
5
  private
5
6
  def bundle_cmd(original, options={})
data/lib/fudge/runner.rb CHANGED
@@ -1,13 +1,18 @@
1
1
  module Fudge
2
+ # Executes the build
2
3
  class Runner
3
4
  def initialize(description)
4
5
  @description = description
5
6
  end
6
7
 
8
+ # Run the specified build
9
+ #
10
+ # @param [String] which_build Defaults to 'default'
7
11
  def run_build(which_build='default', options={})
8
12
  which_build = String.new(which_build)
9
13
 
10
- puts "Running build ".foreground(:cyan) + which_build.bright.foreground(:yellow)
14
+ puts "Running build ".foreground(:cyan) +
15
+ which_build.bright.foreground(:yellow)
11
16
 
12
17
  # Run the build
13
18
  build = @description.builds[which_build.to_sym]
@@ -1,4 +1,5 @@
1
1
  module Fudge
2
+ # Domain specific language for expressing Tasks in the Fudgefile
2
3
  module TaskDSL
3
4
  extend ActiveSupport::Concern
4
5
 
@@ -6,6 +7,7 @@ module Fudge
6
7
  attr_writer :scope
7
8
  end
8
9
 
10
+ # Add self to the scope
9
11
  def scope
10
12
  @scope ||= [self]
11
13
  end
data/lib/fudge/tasks.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module Fudge
2
+ # Define default tasks
2
3
  module Tasks
3
4
  # Registers a task under a given name
4
5
  def self.register(task_class)
@@ -27,5 +28,6 @@ module Fudge
27
28
  require 'fudge/tasks/rake'
28
29
  require 'fudge/tasks/rspec'
29
30
  require 'fudge/tasks/yard'
31
+ require 'fudge/tasks/cane'
30
32
  end
31
33
  end
@@ -0,0 +1,28 @@
1
+ module Fudge
2
+ module Tasks
3
+ # Allow use of Cane complexity and style analyser
4
+ class Cane < Shell
5
+ include Helpers::BundleAware
6
+
7
+ private
8
+
9
+ def cmd(options={})
10
+ cmd = ["cane"] + tty_options
11
+ bundle_cmd(cmd.join(' '), options)
12
+ end
13
+
14
+ def check_for
15
+ /\A\Z/
16
+ end
17
+
18
+ def tty_options
19
+ args = []
20
+ args << "--no-doc" unless options.fetch(:doc, true)
21
+ args << "--no-style" unless options.fetch(:style, true)
22
+ args
23
+ end
24
+ end
25
+
26
+ register Cane
27
+ end
28
+ end
@@ -1,10 +1,7 @@
1
1
  module Fudge
2
2
  module Tasks
3
+ # Provides a sanitized running environment for Bundler
3
4
  class CleanBundlerEnv < CompositeTask
4
- def self.name
5
- :clean_bundler_env
6
- end
7
-
8
5
  def run(options={})
9
6
  old_env = ENV
10
7
  keys = ENV.keys.grep(/BUNDLE|RUBY/)
@@ -1,8 +1,10 @@
1
1
  module Fudge
2
2
  module Tasks
3
+ # Allow for tasks to be combined
3
4
  class CompositeTask < Task
4
5
  attr_accessor :description
5
6
 
7
+ # Define task array
6
8
  def tasks
7
9
  @tasks ||= []
8
10
  end
@@ -10,15 +12,27 @@ module Fudge
10
12
  # Runs the task (by default running all other tasks in order)
11
13
  def run(options={})
12
14
  tasks.each do |t|
13
- args_text = t.respond_to?(:args) && t.args ? t.args.join(', ') : ''
14
-
15
- puts "Running task ".foreground(:blue) +
16
- t.class.name.to_s.foreground(:yellow).bright + ' ' +
17
- args_text.foreground(:yellow).bright
15
+ output_message(t)
18
16
 
19
17
  return unless t.run(options)
20
18
  end
21
19
  end
20
+
21
+ private
22
+
23
+ def join_arguments(t)
24
+ t.respond_to?(:args) && t.args ? t.args.join(', ') : ''
25
+ end
26
+
27
+ def output_message(t)
28
+ args_text = join_arguments(t)
29
+
30
+ puts [
31
+ "Running task".foreground(:blue),
32
+ t.class.name.to_s.foreground(:yellow).bright,
33
+ args_text.foreground(:yellow).bright
34
+ ].join(' ')
35
+ end
22
36
  end
23
37
  end
24
38
  end
@@ -1,13 +1,10 @@
1
1
  module Fudge
2
2
  module Tasks
3
- # A task which runs a number of other tasks in a given directory (relative to the current directory)
3
+ # A task which runs a number of other tasks in a given directory
4
+ # (relative to the current directory)
4
5
  class EachDirectory < CompositeTask
5
6
  attr_accessor :exclude
6
7
 
7
- def self.name
8
- :each_directory
9
- end
10
-
11
8
  def initialize(pattern, *args)
12
9
  super(*args)
13
10
 
@@ -15,18 +12,30 @@ module Fudge
15
12
  end
16
13
 
17
14
  def run(options={})
18
- # Allow either a string (usually "*") or an array of strings with directories
15
+ # Allow either a string (usually "*") or an array of strings
16
+ # with directories
19
17
  redir = @pattern.kind_of?(String) ? Dir[@pattern] : Dir[*@pattern]
20
18
 
21
19
  redir.select { |path| File.directory? path }.each do |dir|
22
20
  next if exclude && exclude.include?(dir)
23
21
 
24
22
  Dir.chdir dir do
25
- puts "--> In directory".foreground(:cyan) + " #{dir}:".foreground(:cyan).bright
23
+ output_dir(dir)
24
+
26
25
  return false unless super
27
26
  end
28
27
  end
29
28
  end
29
+
30
+ private
31
+
32
+ def output_dir(dir)
33
+ message = ""
34
+ message << "--> In directory".foreground(:cyan)
35
+ message << " #{dir}:".foreground(:cyan).bright
36
+
37
+ puts message
38
+ end
30
39
  end
31
40
 
32
41
  register EachDirectory
@@ -1,22 +1,31 @@
1
1
  module Fudge
2
2
  module Tasks
3
- # A task which runs a number of other tasks in a given directory (relative to the current directory)
3
+ # A task which runs a number of other tasks in a given
4
+ # directory (relative to the current directory)
4
5
  class InDirectory < CompositeTask
5
- def self.name
6
- :in_directory
7
- end
8
-
9
6
  def initialize(directory, *args)
10
7
  super
8
+
11
9
  @directory = directory
12
10
  end
13
11
 
14
12
  def run(options={})
15
13
  Dir.chdir @directory do
16
- puts "--> In directory".foreground(:cyan) + " #{@directory}:".foreground(:cyan).bright
14
+ output_dir(@directory)
15
+
17
16
  super
18
17
  end
19
18
  end
19
+
20
+ private
21
+
22
+ def output_dir(dir)
23
+ message = ""
24
+ message << "--> In directory".foreground(:cyan)
25
+ message << " #{dir}:".foreground(:cyan).bright
26
+
27
+ puts message
28
+ end
20
29
  end
21
30
 
22
31
  register InDirectory
@@ -1,12 +1,9 @@
1
1
  module Fudge
2
2
  module Tasks
3
+ # Allow use of rake as a supported task
3
4
  class Rake < Shell
4
5
  include Helpers::BundleAware
5
6
 
6
- def self.name
7
- :rake
8
- end
9
-
10
7
  private
11
8
 
12
9
  def cmd(options={})
@@ -1,27 +1,33 @@
1
1
  module Fudge
2
2
  module Tasks
3
+ # Allow use of RSpec as a task
3
4
  class Rspec < Shell
4
5
  include Helpers::BundleAware
5
6
 
6
7
  attr_accessor :color, :coverage
7
8
 
8
- def self.name
9
- :rspec
10
- end
11
-
12
9
  private
10
+
13
11
  def cmd(options={})
14
12
  self.arguments = 'spec/' if arguments.blank?
15
- bundle_cmd("rspec#{' --tty' unless color == false} #{arguments}", options)
13
+ bundle_cmd("rspec#{tty_options} #{arguments}", options)
14
+ end
15
+
16
+ def tty_options
17
+ ' --tty' unless color == false
16
18
  end
17
19
 
18
20
  def check_for
19
21
  if coverage
20
- [/(\d+\.\d+)%\) covered/, lambda { |matches| matches[1].to_f >= coverage ? true : 'Insufficient Coverage.' }]
22
+ [/(\d+\.\d+)%\) covered/, method(:coverage_checker)]
21
23
  else
22
24
  super
23
25
  end
24
26
  end
27
+
28
+ def coverage_checker(matches)
29
+ matches[1].to_f >= coverage ? true : 'Insufficient Coverage.'
30
+ end
25
31
  end
26
32
 
27
33
  register Rspec
@@ -1,18 +1,19 @@
1
1
  module Fudge
2
2
  module Tasks
3
+ # Allow use of shell commands as tasks
3
4
  class Shell < Task
4
5
  attr_accessor :arguments, :check_for
5
6
 
6
- def self.name
7
- :shell
8
- end
9
-
10
7
  def initialize(*args)
11
8
  self.arguments = super.join(' ')
12
9
  end
13
10
 
11
+ # Execute the shell command
12
+ #
13
+ # @param [Hash] options Any options to pass to the shell
14
14
  def run(options={})
15
15
  @output, success = run_command(cmd(options))
16
+
16
17
  return false unless success
17
18
  return check_for_output
18
19
  end
@@ -1,11 +1,20 @@
1
1
  module Fudge
2
2
  module Tasks
3
+ # Implementation of base Task
3
4
  class Task
4
- attr_reader :args
5
+ attr_reader :args, :options
6
+
7
+ # Default name derived from class name.
8
+ # Can be overriden by specific tasks.
9
+ #
10
+ # @return [Symbol]
11
+ def self.name
12
+ super.demodulize.underscore.downcase.to_sym
13
+ end
5
14
 
6
15
  def initialize(*args)
7
16
  @args = args.dup
8
- options = args.extract_options!
17
+ @options = args.extract_options!
9
18
 
10
19
  options.each do |k,v|
11
20
  send("#{k}=", v) if respond_to?("#{k}=")
@@ -1,27 +1,37 @@
1
1
  module Fudge
2
2
  module Tasks
3
+ # Allow use of Yard as a supported task
3
4
  class Yard < Shell
4
5
  include Helpers::BundleAware
5
6
 
6
7
  attr_accessor :coverage
7
8
 
8
- def self.name
9
- :yard
10
- end
11
-
12
9
  private
13
10
 
14
11
  def cmd(options={})
15
12
  bundle_cmd("yard #{arguments}", options)
16
13
  end
17
14
 
15
+ def arguments
16
+ args = super
17
+ if args.empty?
18
+ "stats --list-undoc"
19
+ else
20
+ args
21
+ end
22
+ end
23
+
18
24
  def check_for
19
25
  if coverage
20
- [/(\d+\.\d+)% documented/, lambda { |matches| matches[1].to_f >= coverage ? true : 'Insufficient Documentation.' }]
26
+ [/(\d+\.\d+)% documented/, method(:coverage_checker)]
21
27
  else
22
28
  super
23
29
  end
24
30
  end
31
+
32
+ def coverage_checker(matches)
33
+ matches[1].to_f >= coverage ? true : 'Insufficient Documentation.'
34
+ end
25
35
  end
26
36
 
27
37
  register Yard
data/lib/fudge/version.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  module Fudge
2
- VERSION = "0.0.2"
2
+ # Define gem version
3
+ VERSION = "0.0.3"
3
4
  end
@@ -63,7 +63,7 @@ describe Fudge::Description do
63
63
  end
64
64
 
65
65
  it "should super method_missing if no task found" do
66
- expect { subject.non_existeng_task :foo, :bar }.to raise_error(NoMethodError)
66
+ expect { subject.no_task :foo, :bar }.to raise_error(NoMethodError)
67
67
  end
68
68
 
69
69
  it "should add tasks recursively to composite tasks" do
@@ -112,39 +112,40 @@ describe Fudge::Description do
112
112
  end.to raise_error Fudge::Exceptions::TaskGroupNotFound
113
113
  end
114
114
 
115
- it "should allow the use of task groups through nested layers of composite tasks" do
116
- subject.task_group :group1 do
117
- subject.task :dummy
118
- end
119
-
120
- subject.build :default do
121
- subject.task :dummy_composite do
122
- subject.task_group :group1
115
+ context "grouped tasks" do
116
+ before :each do
117
+ subject.task_group :group1 do
118
+ subject.task :dummy
123
119
  end
124
120
  end
125
121
 
126
- subject.builds[:default].run
127
- DummyTask.ran.should be_true
128
- end
122
+ it "allows group task reuse in composite tasks" do
123
+ subject.build :default do
124
+ subject.task :dummy_composite do
125
+ subject.task_group :group1
126
+ end
127
+ end
129
128
 
130
- it "should allow the use of task groups through nested layers of composite nodes when options are given" do
131
- subject.task_group :group1 do
132
- subject.task :dummy
129
+ subject.builds[:default].run
130
+ DummyTask.ran.should be_true
133
131
  end
134
132
 
135
- subject.build :default do
136
- subject.task :dummy_composite, :hello, :foobar => true do
137
- subject.task_group :group1
133
+ it "supports when options are given" do
134
+ subject.build :default do
135
+ subject.task :dummy_composite, :hello, :foobar => true do
136
+ subject.task_group :group1
137
+ end
138
138
  end
139
- end
140
139
 
141
- subject.builds[:default].run
140
+ subject.builds[:default].run
142
141
 
143
- # Check that the options are maintained through the call
144
- build_tasks.first.args.should have(2).items
145
- build_tasks.first.args[1][:foobar].should be_true
146
- DummyTask.ran.should be_true
142
+ # Check that the options are maintained through the call
143
+ build_tasks.first.args.should have(2).items
144
+ build_tasks.first.args[1][:foobar].should be_true
145
+ DummyTask.ran.should be_true
146
+ end
147
147
  end
148
+
148
149
  end
149
150
 
150
151
  describe "Callback Hooks" do
@@ -170,7 +171,7 @@ describe Fudge::Description do
170
171
  @ran.should == ['FOO', 'BAR']
171
172
  end
172
173
 
173
- it "should fail the build and stop running callbacks if any of the success hooks fail" do
174
+ it "fails the build HARD when hooks fail" do
174
175
  make_build do
175
176
  subject.on_success { subject.shell 'fail'; subject.shell 'FOO' }
176
177
  subject.on_success { subject.shell 'BAR' }
@@ -213,7 +214,7 @@ describe Fudge::Description do
213
214
  @ran.should == ['WOOP', 'BAR']
214
215
  end
215
216
 
216
- it "should fail the build and stop running callbacks if any of the failure hooks fail" do
217
+ it "fails the build HARD when hooks fail" do
217
218
  make_build do
218
219
  subject.on_failure { subject.shell 'fail'; subject.shell 'FOO' }
219
220
  subject.on_failure { subject.shell 'BAR' }
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fudge::Tasks::Cane do
4
+ it { should be_registered_as :cane }
5
+
6
+ it_should_behave_like 'bundle aware'
7
+
8
+ describe :run do
9
+ it "runs cane on the codebase" do
10
+ subject.should run_command "cane"
11
+ end
12
+
13
+ context 'with :doc => false' do
14
+ subject {described_class.new :doc => false }
15
+
16
+ it "runs with --no-doc" do
17
+ subject.should run_command "cane --no-doc"
18
+ end
19
+ end
20
+
21
+ context 'with :style => false' do
22
+ subject {described_class.new :style => false }
23
+
24
+ it "runs with --no-style" do
25
+ subject.should run_command "cane --no-style"
26
+ end
27
+ end
28
+
29
+ it { should_not succeed_with_output 'any output from cane is bad' }
30
+ it { should succeed_with_output '' }
31
+ end
32
+ end
@@ -25,7 +25,8 @@ describe Fudge::Tasks::EachDirectory do
25
25
  describe :run do
26
26
  let(:task) { TestEachDirectoryTask.new }
27
27
  let(:dirs) do
28
- Dir[File.expand_path('../../../../*', __FILE__)].select { |path| File.directory? path }
28
+ files = Dir[File.expand_path('../../../../*', __FILE__)]
29
+ files.select { |path| File.directory? path }
29
30
  end
30
31
 
31
32
  before :each do
@@ -13,7 +13,8 @@ describe Fudge::Tasks::Rspec do
13
13
  end
14
14
 
15
15
  it "should append any arguments passed in" do
16
- described_class.new('foobar', :color => false).should run_command 'rspec foobar'
16
+ task = described_class.new('foobar', :color => false)
17
+ task.should run_command 'rspec foobar'
17
18
  end
18
19
 
19
20
  it "should default the arguments to spec/" do
@@ -28,7 +28,11 @@ describe Fudge::Tasks::Shell do
28
28
  end
29
29
 
30
30
  context "with a callable to check the matches" do
31
- subject { described_class.new(:ls, :check_for => [/(\d+) files found/, lambda { |matches| matches[1].to_i >= 4 }]) }
31
+ let(:file_count_matcher) { lambda { |matches| matches[1].to_i >= 4 }}
32
+ subject do
33
+ described_class.new :ls,
34
+ :check_for => [/(\d+) files found/, file_count_matcher]
35
+ end
32
36
 
33
37
  it { should_not succeed_with_output "Hello there were 3 files found." }
34
38
  it { should succeed_with_output "Hello there were 4 files found." }
@@ -4,11 +4,23 @@ class MyTask < Fudge::Tasks::Task
4
4
  attr_accessor :blabla
5
5
  end
6
6
 
7
+ class TestNamespace
8
+ class SomeTask < Fudge::Tasks::Task
9
+ end
10
+ end
11
+
7
12
  describe Fudge::Tasks::Task do
8
13
  describe :initialize do
9
14
  it "should accepts options and set them" do
10
15
  task = MyTask.new :blabla => 'foo'
16
+
11
17
  task.blabla.should == 'foo'
12
18
  end
13
19
  end
20
+
21
+ describe :name do
22
+ it "should default to implied name from class name" do
23
+ TestNamespace::SomeTask.name.should == :some_task
24
+ end
25
+ end
14
26
  end
@@ -6,8 +6,13 @@ describe Fudge::Tasks::Yard do
6
6
  it { should be_registered_as :yard }
7
7
 
8
8
  describe :run do
9
+ it "runs stats with undocumented by default" do
10
+ subject.should run_command 'yard stats --list-undoc'
11
+ end
12
+
9
13
  it "should run yard with any arguments passed in" do
10
- described_class.new('-r YardREADME.md').should run_command 'yard -r YardREADME.md'
14
+ task = described_class.new('-r YardREADME.md')
15
+ task.should run_command 'yard -r YardREADME.md'
11
16
  end
12
17
  end
13
18
 
@@ -26,7 +26,8 @@ describe Fudge::Tasks do
26
26
  end
27
27
 
28
28
  it "should raise an exception if the task is not found" do
29
- expect { subject.discover(:something) }.to raise_error Fudge::Exceptions::TaskNotFound
29
+ no_task_error = Fudge::Exceptions::TaskNotFound
30
+ expect { subject.discover(:something) }.to raise_error no_task_error
30
31
  end
31
32
  end
32
33
  end
data/spec/spec_helper.rb CHANGED
@@ -9,14 +9,10 @@ require 'fudge'
9
9
  Dir[File.expand_path('../../spec/support/*', __FILE__)].each { |f| require f }
10
10
 
11
11
  # Get rid of output in specs
12
- # RSpec.configure do |c|
13
- # c.before :each do
14
- # @oldstdout, $stdout = $stdout, StringIO.new
15
- # @oldstderr, $stderr = $stderr, StringIO.new
16
- # end
17
- #
18
- # c.after :each do
19
- # $stdout = @oldstdout
20
- # $stderr = @oldstderr
21
- # end
22
- # end
12
+ RSpec.configure do |c|
13
+ c.around :each do |example|
14
+ hide_stdout do
15
+ example.run
16
+ end
17
+ end
18
+ end
@@ -4,26 +4,54 @@ RSpec::Matchers.define :be_registered_as do |key|
4
4
  end
5
5
  end
6
6
 
7
- RSpec::Matchers.define :run_command do |to_match, args|
8
- match do |subject|
9
- ran = ''
10
- to_stub = subject.is_a?(Fudge::Tasks::Shell) ? subject : Fudge::Tasks::Shell.any_instance
11
7
 
12
- to_stub.stub(:run_command) do |cmd|
13
- ran = cmd
14
- ['dummy output', true]
8
+ module FudgeMatchers
9
+ class Run
10
+ attr_reader :args, :expected, :task
11
+
12
+ def initialize(expected, args={})
13
+ @expected = expected
14
+ @args = args
15
15
  end
16
16
 
17
- subject.run(args || {})
17
+ def matches?(task)
18
+ @task = task
19
+ ran = ''
20
+
21
+ if task.is_a?(Fudge::Tasks::Shell)
22
+ to_stub = task
23
+ else
24
+ to_stub = Fudge::Tasks::Shell.any_instance
25
+ end
26
+
27
+ to_stub.stub(:run_command) do |cmd|
28
+ ran = cmd
29
+ ['dummy output', true]
30
+ end
31
+
32
+ task.run(args || {})
18
33
 
19
- if to_match.is_a? Regexp
20
- ran =~ to_match
21
- else
22
- ran == to_match
34
+ @actual = ran
35
+ if expected.is_a? Regexp
36
+ ran =~ expected
37
+ else
38
+ ran == expected
39
+ end
40
+ end
41
+
42
+ def failure_message_for_should
43
+ message = ""
44
+ message << "Expected task :#{@task.class.name} "
45
+ message << "to run:\n #{@expected}\n"
46
+ message << "but it ran:\n #{@actual}"
23
47
  end
24
48
  end
25
49
  end
26
50
 
51
+ def run_command(cmd, options={})
52
+ FudgeMatchers::Run.new cmd, options
53
+ end
54
+
27
55
  RSpec::Matchers.define :succeed_with_output do |output|
28
56
  match do |subject|
29
57
  subject.stub(:run_command).and_return([output, true])
@@ -0,0 +1,9 @@
1
+ def hide_stdout
2
+ out = $stdout
3
+ err = $stderr
4
+ $stdout = StringIO.new
5
+ $stderr = StringIO.new
6
+ yield
7
+ $stdout = out
8
+ $stderr = err
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fudge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-17 00:00:00.000000000 Z
12
+ date: 2012-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: redcarpet
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: rspec
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +123,22 @@ dependencies:
107
123
  - - ! '>='
108
124
  - !ruby/object:Gem::Version
109
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: cane
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
110
142
  - !ruby/object:Gem::Dependency
111
143
  name: RedCloth
112
144
  requirement: !ruby/object:Gem::Requirement
@@ -213,7 +245,6 @@ files:
213
245
  - lib/fudge.rb
214
246
  - lib/fudge/tasks.rb
215
247
  - lib/fudge/helpers/bundle_aware.rb
216
- - lib/fudge/railtie.rb
217
248
  - lib/fudge/cli.rb
218
249
  - lib/fudge/parser.rb
219
250
  - lib/fudge/version.rb
@@ -224,6 +255,7 @@ files:
224
255
  - lib/fudge/tasks/yard.rb
225
256
  - lib/fudge/tasks/rspec.rb
226
257
  - lib/fudge/tasks/in_directory.rb
258
+ - lib/fudge/tasks/cane.rb
227
259
  - lib/fudge/tasks/composite_task.rb
228
260
  - lib/fudge/tasks/shell.rb
229
261
  - lib/fudge/tasks/rake.rb
@@ -232,7 +264,6 @@ files:
232
264
  - lib/fudge/build.rb
233
265
  - lib/fudge/description.rb
234
266
  - lib/fudge/task_dsl.rb
235
- - lib/tasks/fudge.rake
236
267
  - spec/lib/fudge/description_spec.rb
237
268
  - spec/lib/fudge/build_spec.rb
238
269
  - spec/lib/fudge/parser_spec.rb
@@ -243,12 +274,14 @@ files:
243
274
  - spec/lib/fudge/tasks/each_directory_spec.rb
244
275
  - spec/lib/fudge/tasks/yard_spec.rb
245
276
  - spec/lib/fudge/tasks/in_directory_spec.rb
277
+ - spec/lib/fudge/tasks/cane_spec.rb
246
278
  - spec/lib/fudge/tasks/task_spec.rb
247
279
  - spec/lib/fudge/tasks/rspec_spec.rb
248
280
  - spec/lib/fudge/tasks/bundler_spec.rb
249
281
  - spec/lib/fudge/tasks/shell_spec.rb
250
282
  - spec/lib/fudge/cli_spec.rb
251
283
  - spec/lib/fudge/exceptions_spec.rb
284
+ - spec/support/output.rb
252
285
  - spec/support/dummy_task.rb
253
286
  - spec/support/matchers.rb
254
287
  - spec/support/tmpdir.rb
@@ -289,12 +322,14 @@ test_files:
289
322
  - spec/lib/fudge/tasks/each_directory_spec.rb
290
323
  - spec/lib/fudge/tasks/yard_spec.rb
291
324
  - spec/lib/fudge/tasks/in_directory_spec.rb
325
+ - spec/lib/fudge/tasks/cane_spec.rb
292
326
  - spec/lib/fudge/tasks/task_spec.rb
293
327
  - spec/lib/fudge/tasks/rspec_spec.rb
294
328
  - spec/lib/fudge/tasks/bundler_spec.rb
295
329
  - spec/lib/fudge/tasks/shell_spec.rb
296
330
  - spec/lib/fudge/cli_spec.rb
297
331
  - spec/lib/fudge/exceptions_spec.rb
332
+ - spec/support/output.rb
298
333
  - spec/support/dummy_task.rb
299
334
  - spec/support/matchers.rb
300
335
  - spec/support/tmpdir.rb
data/lib/fudge/railtie.rb DELETED
@@ -1,17 +0,0 @@
1
- require 'rails'
2
- require 'fudge'
3
-
4
- module Fudge
5
-
6
- # Adds behaviours to Rails
7
- class Railtie < Rails::Railtie
8
- railtie_name :fudge
9
- rake_tasks do
10
- begin
11
-
12
- Dir[ File.join(File.dirname(__FILE__), '../tasks/*.rake')] .each { |f| load f } #Load static tasks
13
-
14
- end
15
- end
16
- end
17
- end
data/lib/tasks/fudge.rake DELETED
@@ -1,7 +0,0 @@
1
-
2
- namespace :fudge do
3
- desc "Run the build with Fudge"
4
- task :fudge do
5
- `fudge build`
6
- end
7
- end