fudge 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/fudge +9 -0
- data/lib/fudge.rb +16 -0
- data/lib/fudge/build.rb +31 -0
- data/lib/fudge/cli.rb +29 -0
- data/lib/fudge/description.rb +53 -0
- data/lib/fudge/exceptions.rb +31 -0
- data/lib/fudge/helpers.rb +5 -0
- data/lib/fudge/helpers/bundle_aware.rb +14 -0
- data/lib/fudge/parser.rb +12 -0
- data/lib/fudge/railtie.rb +17 -0
- data/lib/fudge/runner.rb +25 -0
- data/lib/fudge/task_dsl.rb +41 -0
- data/lib/fudge/tasks.rb +31 -0
- data/lib/fudge/tasks/clean_bundler_env.rb +24 -0
- data/lib/fudge/tasks/composite_task.rb +24 -0
- data/lib/fudge/tasks/each_directory.rb +34 -0
- data/lib/fudge/tasks/in_directory.rb +24 -0
- data/lib/fudge/tasks/rake.rb +19 -0
- data/lib/fudge/tasks/rspec.rb +29 -0
- data/lib/fudge/tasks/shell.rb +76 -0
- data/lib/fudge/tasks/task.rb +18 -0
- data/lib/fudge/tasks/yard.rb +29 -0
- data/lib/fudge/version.rb +3 -0
- data/lib/tasks/fudge.rake +7 -0
- data/spec/lib/fudge/build_spec.rb +5 -0
- data/spec/lib/fudge/cli_spec.rb +76 -0
- data/spec/lib/fudge/description_spec.rb +241 -0
- data/spec/lib/fudge/exceptions_spec.rb +36 -0
- data/spec/lib/fudge/parser_spec.rb +23 -0
- data/spec/lib/fudge/runner_spec.rb +25 -0
- data/spec/lib/fudge/tasks/bundler_spec.rb +39 -0
- data/spec/lib/fudge/tasks/composite_task_spec.rb +60 -0
- data/spec/lib/fudge/tasks/each_directory_spec.rb +57 -0
- data/spec/lib/fudge/tasks/in_directory_spec.rb +39 -0
- data/spec/lib/fudge/tasks/rake_spec.rb +18 -0
- data/spec/lib/fudge/tasks/rspec_spec.rb +36 -0
- data/spec/lib/fudge/tasks/shell_spec.rb +38 -0
- data/spec/lib/fudge/tasks/task_spec.rb +14 -0
- data/spec/lib/fudge/tasks/yard_spec.rb +25 -0
- data/spec/lib/fudge/tasks_spec.rb +33 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/dummy_task.rb +40 -0
- data/spec/support/matchers.rb +47 -0
- data/spec/support/tmpdir.rb +12 -0
- metadata +302 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Fudge::Exceptions
|
4
|
+
describe Base do
|
5
|
+
it { should be_a StandardError }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe BuildFailed do
|
9
|
+
it { should be_a Base }
|
10
|
+
its(:message) { should be_a String }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe TaskNotFound do
|
14
|
+
subject { described_class.new :foo }
|
15
|
+
|
16
|
+
it { should be_a Base }
|
17
|
+
|
18
|
+
its(:message) { should be_a String }
|
19
|
+
|
20
|
+
it "should take a task name as a parameter" do
|
21
|
+
expect { described_class.new }.to raise_error ArgumentError
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe TaskGroupNotFound do
|
26
|
+
subject { described_class.new :foo }
|
27
|
+
|
28
|
+
it { should be_a Base }
|
29
|
+
|
30
|
+
its(:message) { should be_a String }
|
31
|
+
|
32
|
+
it "should take a task group name as a parameter" do
|
33
|
+
expect { described_class.new }.to raise_error ArgumentError
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fudge::Parser do
|
4
|
+
use_tmp_dir
|
5
|
+
|
6
|
+
describe :parse do
|
7
|
+
before :each do
|
8
|
+
@path = 'FudgeFile'
|
9
|
+
|
10
|
+
File.open(@path, 'w') do |f|
|
11
|
+
f.write('@foo = :bar')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should read a file and evaluate it" do
|
16
|
+
subject.parse(@path).should be_a Fudge::Description
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should pass the contents to the new description" do
|
20
|
+
subject.parse(@path).instance_variable_get(:@foo).should == :bar
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fudge::Runner do
|
4
|
+
let(:input) do
|
5
|
+
StringIO.new('build :default do; task :dummy; end').tap do |s|
|
6
|
+
s.stub(:path).and_return('')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
let(:description) { Fudge::Description.new(input) }
|
10
|
+
subject { described_class.new(description) }
|
11
|
+
|
12
|
+
describe :run_build do
|
13
|
+
it "should run the default task in the description" do
|
14
|
+
subject.run_build
|
15
|
+
|
16
|
+
DummyTask.ran.should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should raise an exception if the build fails" do
|
20
|
+
Fudge::Build.any_instance.stub(:run).and_return(false)
|
21
|
+
|
22
|
+
expect { subject.run_build }.to raise_error Fudge::Exceptions::BuildFailed
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestBundlerAwareTask
|
4
|
+
def self.name
|
5
|
+
:test_bundle_aware
|
6
|
+
end
|
7
|
+
|
8
|
+
def run(options = {})
|
9
|
+
options[:bundler] == true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestNonBundlerAwareTask
|
14
|
+
def self.name
|
15
|
+
:test_non_bundle_aware
|
16
|
+
end
|
17
|
+
|
18
|
+
def run(options={})
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Fudge::Tasks::CleanBundlerEnv do
|
24
|
+
it { should be_registered_as :clean_bundler_env }
|
25
|
+
|
26
|
+
describe :run do
|
27
|
+
let(:bundle_aware_task) { TestBundlerAwareTask.new }
|
28
|
+
let(:non_bundle_aware_task) { TestNonBundlerAwareTask.new }
|
29
|
+
|
30
|
+
context "with a bundle aware task" do
|
31
|
+
it "should run the bundle dependent tasks successfully" do
|
32
|
+
subject.tasks << bundle_aware_task
|
33
|
+
subject.tasks << non_bundle_aware_task
|
34
|
+
|
35
|
+
subject.run.should be_true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class DummyTask2 < DummyTask
|
4
|
+
def self.name
|
5
|
+
:dummy2
|
6
|
+
end
|
7
|
+
end
|
8
|
+
Fudge::Tasks.register(DummyTask2)
|
9
|
+
|
10
|
+
describe Fudge::Tasks::CompositeTask do
|
11
|
+
subject { described_class.new do; end }
|
12
|
+
|
13
|
+
describe :run do
|
14
|
+
before :each do
|
15
|
+
subject.tasks << DummyTask.new
|
16
|
+
subject.tasks << DummyTask2.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should run all tasks defined and return true if they all succeed" do
|
20
|
+
DummyTask.any_instance.should_receive(:run).and_return(true)
|
21
|
+
DummyTask2.any_instance.should_receive(:run).and_return(true)
|
22
|
+
|
23
|
+
subject.run.should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return false if any of the tasks fail" do
|
27
|
+
DummyTask.any_instance.should_receive(:run).and_return(false)
|
28
|
+
DummyTask2.any_instance.should_not_receive(:run)
|
29
|
+
|
30
|
+
subject.run.should be_false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "Using TaskDSL" do
|
35
|
+
describe :task do
|
36
|
+
class AnotherCompositeTask < Fudge::Tasks::CompositeTask
|
37
|
+
include Fudge::TaskDSL
|
38
|
+
|
39
|
+
def initialize(*args)
|
40
|
+
super
|
41
|
+
|
42
|
+
task :shell, 'foo', 'bar'
|
43
|
+
task :dummy_composite do
|
44
|
+
task :dummy
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
subject { AnotherCompositeTask.new }
|
50
|
+
|
51
|
+
it "should define a task for each new instance of the composite task" do
|
52
|
+
subject.should run_command 'foo bar'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should support defining composite tasks" do
|
56
|
+
subject.tasks[1].tasks.first.should be_a DummyTask
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestEachDirectoryTask
|
4
|
+
attr_accessor :pwds
|
5
|
+
def self.name
|
6
|
+
:test_each_directory
|
7
|
+
end
|
8
|
+
|
9
|
+
def run(options={})
|
10
|
+
(self.pwds ||= []) << FileUtils.pwd
|
11
|
+
end
|
12
|
+
end
|
13
|
+
Fudge::Tasks.register(TestEachDirectoryTask)
|
14
|
+
|
15
|
+
describe Fudge::Tasks::EachDirectory do
|
16
|
+
subject { described_class.new 'spec/*' }
|
17
|
+
it { should be_registered_as :each_directory }
|
18
|
+
|
19
|
+
describe :initialize do
|
20
|
+
it "should take a directory pattern as first argument" do
|
21
|
+
expect { described_class.new }.to raise_error ArgumentError
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe :run do
|
26
|
+
let(:task) { TestEachDirectoryTask.new }
|
27
|
+
let(:dirs) do
|
28
|
+
Dir[File.expand_path('../../../../*', __FILE__)].select { |path| File.directory? path }
|
29
|
+
end
|
30
|
+
|
31
|
+
before :each do
|
32
|
+
subject.tasks << task
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should change to the given directories and run child tasks" do
|
36
|
+
subject.run
|
37
|
+
|
38
|
+
task.pwds.should == dirs
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should allow explicit specification of directories through an array" do
|
42
|
+
ed2 = described_class.new ["spec/lib","spec/support"]
|
43
|
+
ed2.tasks << task
|
44
|
+
ed2.run
|
45
|
+
task.pwds.should == dirs.sort
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should respect the order of the directories as specified" do
|
49
|
+
ed2 = described_class.new ["spec/support","spec/lib"]
|
50
|
+
ed2.tasks << task
|
51
|
+
ed2.run
|
52
|
+
task.pwds.should_not == dirs.sort
|
53
|
+
task.pwds.sort.should == dirs.sort
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestInDirectoryTask
|
4
|
+
attr_accessor :pwd
|
5
|
+
def self.name
|
6
|
+
:test_in_directory
|
7
|
+
end
|
8
|
+
|
9
|
+
def run(options={})
|
10
|
+
self.pwd = FileUtils.pwd
|
11
|
+
end
|
12
|
+
end
|
13
|
+
Fudge::Tasks.register(TestInDirectoryTask)
|
14
|
+
|
15
|
+
describe Fudge::Tasks::InDirectory do
|
16
|
+
subject { described_class.new 'spec' }
|
17
|
+
it { should be_registered_as :in_directory }
|
18
|
+
|
19
|
+
describe :initialize do
|
20
|
+
it "should take a directory as first argument" do
|
21
|
+
expect { described_class.new }.to raise_error ArgumentError
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe :run do
|
26
|
+
let(:task) { TestInDirectoryTask.new }
|
27
|
+
let(:path) { File.expand_path('spec', FileUtils.pwd) }
|
28
|
+
|
29
|
+
before :each do
|
30
|
+
subject.tasks << task
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should change to the given directory and run child tasks" do
|
34
|
+
subject.run
|
35
|
+
|
36
|
+
task.pwd.should == path
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fudge::Tasks::Rake do
|
4
|
+
it { should be_registered_as :rake }
|
5
|
+
it { should be_a Fudge::Tasks::Shell }
|
6
|
+
|
7
|
+
describe :run do
|
8
|
+
it "should be rake by default" do
|
9
|
+
subject.should run_command 'rake '
|
10
|
+
end
|
11
|
+
|
12
|
+
it_should_behave_like 'bundle aware'
|
13
|
+
|
14
|
+
it "should add any arguments given" do
|
15
|
+
described_class.new('db:migrate').should run_command 'rake db:migrate'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fudge::Tasks::Rspec do
|
4
|
+
it { should be_registered_as :rspec }
|
5
|
+
|
6
|
+
describe :run do
|
7
|
+
it "should turn on color if not specified" do
|
8
|
+
subject.should run_command /--tty/
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should turn off color if specified" do
|
12
|
+
described_class.new(:color => false).should_not run_command /--tty/
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should append any arguments passed in" do
|
16
|
+
described_class.new('foobar', :color => false).should run_command 'rspec foobar'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should default the arguments to spec/" do
|
20
|
+
described_class.new(:color => false).should run_command 'rspec spec/'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
it_should_behave_like 'bundle aware'
|
26
|
+
|
27
|
+
describe :coverage do
|
28
|
+
subject { described_class.new :coverage => 99 }
|
29
|
+
|
30
|
+
it { should_not succeed_with_output 'some dummy output with no coverage' }
|
31
|
+
it { should_not succeed_with_output '98.99999%) covered' }
|
32
|
+
it { should_not succeed_with_output '0.00%) covered' }
|
33
|
+
it { should succeed_with_output '99.99999%) covered' }
|
34
|
+
it { should succeed_with_output '100.0%) covered' }
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fudge::Tasks::Shell do
|
4
|
+
describe :run do
|
5
|
+
it "should take a command and run it" do
|
6
|
+
described_class.new(:ls).should run_command 'ls'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should add any arguments given" do
|
10
|
+
described_class.new(:ls, '-l', '-a').should run_command 'ls -l -a'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return false for an unsuccessful command" do
|
14
|
+
described_class.new(:ls, '--newnre').run.should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return true for a successful command" do
|
18
|
+
described_class.new(:ls).run.should be_true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe :check_for do
|
23
|
+
context "with no callable to check the matches" do
|
24
|
+
subject { described_class.new(:ls, :check_for => /4 files found/) }
|
25
|
+
|
26
|
+
it { should succeed_with_output "Hello there were 4 files found." }
|
27
|
+
it { should_not succeed_with_output "Hellow there were 5 files found." }
|
28
|
+
end
|
29
|
+
|
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 }]) }
|
32
|
+
|
33
|
+
it { should_not succeed_with_output "Hello there were 3 files found." }
|
34
|
+
it { should succeed_with_output "Hello there were 4 files found." }
|
35
|
+
it { should succeed_with_output "Hellow there were 5 files found." }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class MyTask < Fudge::Tasks::Task
|
4
|
+
attr_accessor :blabla
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Fudge::Tasks::Task do
|
8
|
+
describe :initialize do
|
9
|
+
it "should accepts options and set them" do
|
10
|
+
task = MyTask.new :blabla => 'foo'
|
11
|
+
task.blabla.should == 'foo'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fudge::Tasks::Yard do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
it { should be_registered_as :yard }
|
7
|
+
|
8
|
+
describe :run do
|
9
|
+
it "should run yard with any arguments passed in" do
|
10
|
+
described_class.new('-r YardREADME.md').should run_command 'yard -r YardREADME.md'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_behave_like 'bundle aware'
|
15
|
+
|
16
|
+
describe :coverage do
|
17
|
+
subject { described_class.new :coverage => 99 }
|
18
|
+
|
19
|
+
it { should_not succeed_with_output 'some dummy output with no coverage' }
|
20
|
+
it { should_not succeed_with_output '98.99999% documented' }
|
21
|
+
it { should_not succeed_with_output '0.00% documented' }
|
22
|
+
it { should succeed_with_output '99.99999% documented' }
|
23
|
+
it { should succeed_with_output '100.0% documented' }
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestTask
|
4
|
+
def self.name
|
5
|
+
:foo
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Fudge::Tasks do
|
10
|
+
describe "Class Methods" do
|
11
|
+
subject { described_class }
|
12
|
+
|
13
|
+
describe :register do
|
14
|
+
it "should register a task for a given symbol" do
|
15
|
+
subject.register(TestTask)
|
16
|
+
|
17
|
+
subject.discover(:foo).should == TestTask
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe :discover do
|
22
|
+
it "should return the registered class for the given symbol" do
|
23
|
+
subject.register(TestTask)
|
24
|
+
|
25
|
+
subject.discover(:foo).should == TestTask
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should raise an exception if the task is not found" do
|
29
|
+
expect { subject.discover(:something) }.to raise_error Fudge::Exceptions::TaskNotFound
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|