anvil-core 0.4.2 → 0.5.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -4
  3. data/VERSION +1 -1
  4. data/lib/anvil/cli.rb +30 -19
  5. data/lib/anvil/extensions_manager.rb +1 -1
  6. data/lib/anvil/options_detector.rb +20 -0
  7. data/lib/anvil/parser.rb +5 -0
  8. data/lib/anvil/task.rb +5 -6
  9. data/lib/anvil/task/options.rb +2 -0
  10. data/lib/anvil/task/repositories.rb +1 -1
  11. data/lib/anvil/versioner.rb +1 -0
  12. data/lib/tasks/gem/build_task.rb +1 -1
  13. data/lib/tasks/gem/bump_task.rb +1 -1
  14. data/lib/tasks/gem/release_task.rb +1 -1
  15. data/lib/tasks/help_task.rb +2 -2
  16. data/lib/tasks/projects/add_task.rb +2 -5
  17. data/lib/tasks/projects/list_task.rb +1 -1
  18. data/spec/lib/anvil/cli_spec.rb +5 -5
  19. data/spec/lib/anvil/config_spec.rb +8 -13
  20. data/spec/lib/anvil/extensions_manager_spec.rb +2 -2
  21. data/spec/lib/anvil/parser_spec.rb +1 -1
  22. data/spec/lib/anvil/task/naming_spec.rb +2 -2
  23. data/spec/lib/anvil/task/projects_spec.rb +1 -1
  24. data/spec/lib/anvil/task_spec.rb +19 -14
  25. data/spec/lib/anvil/versioner_spec.rb +5 -5
  26. data/spec/lib/tasks/gem/build_task_spec.rb +3 -3
  27. data/spec/lib/tasks/gem/bump_task_spec.rb +7 -5
  28. data/spec/lib/tasks/gem/release_task_spec.rb +3 -3
  29. data/spec/lib/tasks/projects/add_task_spec.rb +2 -1
  30. data/spec/spec_helper.rb +13 -6
  31. data/spec/support/{fixtures → dummy_tasks}/dummy_after_task.rb +0 -0
  32. data/spec/support/{fixtures → dummy_tasks}/dummy_assure.rb +0 -0
  33. data/spec/support/{fixtures → dummy_tasks}/dummy_before_task.rb +0 -0
  34. data/spec/support/{fixtures → dummy_tasks}/dummy_failed_assure.rb +0 -0
  35. data/spec/support/{fixtures → dummy_tasks}/dummy_task.rb +0 -0
  36. data/spec/support/{fixtures → dummy_tasks}/foo/dummy_task.rb +0 -0
  37. data/spec/support/{dot_anvil → fixtures}/config.rb +1 -1
  38. data/spec/support/shared/config_mock.rb +17 -0
  39. metadata +38 -39
  40. data/spec/support/shared/config_context.rb +0 -12
  41. data/spec/support/shared/fake_fs_context.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cbc3597b0a252a969f4a00ade732c8e8128ba7f
4
- data.tar.gz: 60f784361da58c2b46d68646dd8c380aa93a28fe
3
+ metadata.gz: d5d7e961a633411eb45ceb405a568842370a3eed
4
+ data.tar.gz: 00a6cebfdbe8811e733670b064af7ccff0fc3642
5
5
  SHA512:
6
- metadata.gz: e2375445573b0816511069450ea8d95fc543bf2f156a5aeb5c8d7fe946e8c7aa40ac6eff003b008fa5a240ce5c04eaf048cf058cfd241d1d36a8ec7a982d8c45
7
- data.tar.gz: b5be65b34d1e8c0fa6e8c58f805a01df857dde02cb5611c0865f451aa75542d396b255bdacd60d9acbd5ce461be24ecc930a242f86ae1285f9f4a2e5d90805ca
6
+ metadata.gz: d40908e160de0e79fa3215722ba546117846db2afec7df5e02eebb669a7f85e17cae623b87fc5381877f0bdd82ab63e059cf51bdb22eb047d061b2dc7e5aae05
7
+ data.tar.gz: 00b6901c779416e932aea2e02b91fe5d622d6c700a60033a6ab4bbb65909a8b8039999f11acea029b8934155905b2ad753e72cb04a1820e09ffcee726cecfcd2
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Anvil
2
2
 
3
- Anvil is a tool for the real craftsmen to build its own tools.
3
+ Anvil is a tool for the real craftspeople to build their own tools.
4
4
 
5
5
  [![Build Status](https://travis-ci.org/anvil-src/anvil-core.png?branch=master)](https://travis-ci.org/anvil-src/anvil-core)
6
6
  [![Gem Version](https://badge.fury.io/rb/anvil-core.svg)](http://badge.fury.io/rb/anvil-core)
@@ -11,8 +11,8 @@ Anvil tries to be a framework for building command line applications
11
11
  to automate tedious tasks like apps or gems releasing process. Pull
12
12
  request updating, etc.
13
13
 
14
- It's purpose is to provide an easy to use Object Oriented toolset
15
- that developers can use to automate par of its day to day work.
14
+ It's purpose is to provide an easy to use Object Oriented toolset that
15
+ developers can use to automate par of its day to day work.
16
16
 
17
17
  Things like:
18
18
 
@@ -23,7 +23,8 @@ Things like:
23
23
 
24
24
  ## Sample tasks
25
25
 
26
- You can find some sample tasks in the samples directory, if you want to give them a try, clone this project and do:
26
+ You can find some sample tasks in the samples directory, if you want
27
+ to give them a try, clone this project and do:
27
28
 
28
29
  ```shell
29
30
  ANVIL_EXTENSIONS_DIR=./sample bin/anvil
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.5.0
@@ -6,11 +6,11 @@ require 'tasks/help_task'
6
6
  module Anvil
7
7
  # Anvil command line interface
8
8
  class Cli
9
- HELP = <<-HELP
9
+ HELP_HEADER = <<-HELP_HEADER
10
10
  Anvil is a tool for making your life easier.
11
11
 
12
12
  Available tasks:
13
- HELP
13
+ HELP_HEADER
14
14
 
15
15
  # Runs a task or prints its help if it needs arguments
16
16
  #
@@ -19,11 +19,10 @@ HELP
19
19
  def run(argv)
20
20
  load_tasks
21
21
 
22
- if argv.empty?
23
- print_help
24
- else
25
- build_task(argv).run
26
- end
22
+ return build_task(argv).run unless argv.empty?
23
+
24
+ print_help_header
25
+ print_help_body
27
26
  end
28
27
 
29
28
  def load_tasks
@@ -41,30 +40,42 @@ HELP
41
40
  klazz.new(*klazz.parse_options!(arguments))
42
41
  rescue NameError
43
42
  task_not_found(task_name)
44
- exit(FALSE)
43
+ exit false
45
44
  rescue ArgumentError
46
- help(task_name)
47
- exit(FALSE)
45
+ bad_arguments(task_name)
46
+ exit false
48
47
  end
49
48
 
50
- def task_not_found(task_name)
51
- printf("Task '#{task_name}' not found\n\n")
52
- print_help
49
+ def task_not_found(task_name = nil)
50
+ Anvil.logger.info "Task '#{task_name}' not found"
51
+ Anvil.logger.info('Maybe you mean one of the following') if task_name
52
+ Anvil.logger.info("\n")
53
+ print_help_body task_name
53
54
  end
54
55
 
55
- def help(task_name)
56
- printf("Wrong number of arguments.\n\n")
56
+ def bad_arguments(task_name)
57
+ Anvil.logger.info("Wrong number of arguments.\n")
57
58
  HelpTask.run(task_name)
58
59
  end
59
60
 
60
- def print_help
61
- printf('%s', HELP)
61
+ def print_help_body(task_name = nil)
62
+ task_list(task_name).each { |task| print_task_line(task) }
63
+ end
64
+
65
+ def task_list(task_name)
62
66
  tasks = Anvil::ExtensionsManager.tasks_by_name
63
- tasks.each { |task| print_task_line(task) }
67
+
68
+ return tasks unless task_name
69
+ tasks.select { |task| task.to_s.underscore =~ /#{task_name}/ }
64
70
  end
65
71
 
66
72
  def print_task_line(task)
67
- printf("%-20s %s\n", task.task_name, task.description)
73
+ message = format '%-20s %s', task.task_name, task.description
74
+ Anvil.logger.info message
75
+ end
76
+
77
+ def print_help_header
78
+ Anvil.logger.info HELP_HEADER
68
79
  end
69
80
  end
70
81
  end
@@ -5,7 +5,7 @@ require 'anvil/task'
5
5
  require 'rugged'
6
6
 
7
7
  module Anvil
8
- # Manage loading and finding anvil tasks
8
+ # Manage loading and finding anvil tasks and config extensions
9
9
  class ExtensionsManager
10
10
  PATTERNS = {
11
11
  tasks: '/tasks/**/*_task.rb',
@@ -0,0 +1,20 @@
1
+ module Anvil
2
+ # Detect whether the options parser has parsed any option or not in
3
+ # order, for example, to write the required help for them.
4
+ class OptionsDetector
5
+ attr_accessor :has_options
6
+
7
+ def on(*_, &_block)
8
+ self.has_options = true
9
+ end
10
+
11
+ def arguments(*_, &_block)
12
+ end
13
+
14
+ def detect_options(&block)
15
+ instance_eval(&block)
16
+
17
+ has_options
18
+ end
19
+ end
20
+ end
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'anvil/task'
4
+ require 'anvil/options_detector'
4
5
 
5
6
  module Anvil
6
7
  # Parser for anvil command line arguments and options
@@ -39,5 +40,9 @@ module Anvil
39
40
  task_klass = Anvil::Task.from_name(name)
40
41
  instance_eval(&task_klass.parser_block) if task_klass.parser_block
41
42
  end
43
+
44
+ def detect_options(&block)
45
+ OptionsDetector.new.detect_options(&block)
46
+ end
42
47
  end
43
48
  end
@@ -22,13 +22,12 @@ module Anvil
22
22
  #
23
23
  # @return [Object, nil] anything the task might return
24
24
  def run
25
- if run_assures
26
- run_before_callbacks
27
- task_return_value = run_task
28
- run_after_callbacks
25
+ return unless run_assures
26
+ run_before_callbacks
27
+ task_return_value = run_task
28
+ run_after_callbacks
29
29
 
30
- task_return_value
31
- end
30
+ task_return_value
32
31
  end
33
32
 
34
33
  def logger
@@ -32,6 +32,8 @@ module Anvil
32
32
  parser.separator description
33
33
  end
34
34
 
35
+ return parser unless parser.detect_options(&block)
36
+
35
37
  parser.separator ''
36
38
  parser.separator 'Available options: '
37
39
  parser.instance_eval(&block)
@@ -5,7 +5,7 @@ module Anvil
5
5
  # Tools to work with github repositories
6
6
  module Repositories
7
7
  def resolve_url(url)
8
- if url =~ /^\w+\/\w+$/
8
+ if url =~ /^[\w\W]+\/[\w\W]+$/
9
9
  "git@github.com:#{url}"
10
10
  else
11
11
  url
@@ -1,3 +1,4 @@
1
+ require 'anvil'
1
2
  require 'semantic/version'
2
3
 
3
4
  module Anvil
@@ -6,7 +6,7 @@ class Gem::BuildTask < Anvil::Task
6
6
  description 'Builds a gem for you and can install it on your system.'
7
7
 
8
8
  parser do
9
- arguments %w[gemspec_file]
9
+ arguments %w(gemspec_file)
10
10
 
11
11
  on('-i', '--[no-]install', 'Install gem') do |i|
12
12
  options[:install] = i
@@ -26,7 +26,7 @@ class Gem::BumpTask < Anvil::Task
26
26
  def task
27
27
  prepare_repo
28
28
  version = bump(read_version)
29
- write_version version
29
+ write_version version.dup.to_s
30
30
 
31
31
  version
32
32
  end
@@ -23,7 +23,7 @@ class Gem::ReleaseTask < Anvil::Task
23
23
  version = bump
24
24
  gem_file = build
25
25
 
26
- push gem_file, version
26
+ push gem_file, version.dup.to_s
27
27
  end
28
28
 
29
29
  protected
@@ -16,10 +16,10 @@ class HelpTask < Anvil::Task
16
16
  def task
17
17
  return default_message unless task_name.present?
18
18
  klazz = Anvil::Task.from_name(task_name)
19
- printf(klazz.help)
19
+ Anvil.logger.info(klazz.help)
20
20
  end
21
21
 
22
22
  def default_message
23
- printf(self.class.help)
23
+ Anvil.logger.info(self.class.help)
24
24
  end
25
25
  end
@@ -7,14 +7,11 @@ module Projects
7
7
  class AddTask < Anvil::Task
8
8
  include Anvil::Task::Repositories
9
9
  description 'Adds a new project for anvil.'
10
-
11
- parser do
12
- arguments %w[name repository]
13
- end
10
+ parser { arguments %w(name repository) }
14
11
 
15
12
  attr_reader :name, :repo
16
13
 
17
- def initialize(name, repo, options = {})
14
+ def initialize(name, repo, _options = {})
18
15
  @name = name
19
16
  @repo = repo
20
17
  end
@@ -4,7 +4,7 @@ module Projects
4
4
  class ListTask < Anvil::Task
5
5
  description 'List the projects that anvil can manage.'
6
6
 
7
- def initialize(options = {}); end
7
+ def initialize(_options = {}); end
8
8
 
9
9
  def task
10
10
  Dir.chdir(Anvil::Config.base_projects_path) { list_projects(projects) }
@@ -8,9 +8,9 @@ describe Anvil::Cli do
8
8
 
9
9
  context 'with a task name' do
10
10
  before do
11
- dummy_task.should_receive(:new)
11
+ expect(dummy_task).to receive(:new)
12
12
  .with('arg1', 'arg2', argument: 'value').and_call_original
13
- subject.should_not_receive(:print_help)
13
+ expect(subject).to_not receive(:print_help)
14
14
  end
15
15
 
16
16
  it('runs the task in the first parameter') { subject.run argv }
@@ -18,7 +18,7 @@ describe Anvil::Cli do
18
18
 
19
19
  describe '#build_task' do
20
20
  it 'builds the task and parses the arguments' do
21
- subject.build_task(argv).options.should == { argument: 'value' }
21
+ expect(subject.build_task(argv).options).to eq({ argument: 'value' })
22
22
  end
23
23
 
24
24
  context 'if the task is not found' do
@@ -37,7 +37,7 @@ describe Anvil::Cli do
37
37
  let(:argv) { %w[foo:dummy arg1 arg2 arg3 arg4 arg5 arg6 arg7] }
38
38
 
39
39
  it 'prints task list and exits' do
40
- expect(subject).to receive(:help).with('foo:dummy')
40
+ expect(subject).to receive(:bad_arguments).with('foo:dummy')
41
41
  expect do
42
42
  subject.build_task(argv)
43
43
  end.to raise_error(SystemExit)
@@ -47,7 +47,7 @@ describe Anvil::Cli do
47
47
 
48
48
  context 'without a task name' do
49
49
  let(:argv) { [] }
50
- before { subject.should_receive(:print_help) }
50
+ before { expect(subject).to receive(:print_help_body) }
51
51
  it('prints the help') { subject.run argv }
52
52
  end
53
53
  end
@@ -1,24 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Anvil::Config, fakefs: true do
3
+ describe Anvil::Config do
4
4
  subject { Anvil::Config }
5
- before { Anvil::Config.reset }
5
+ before { Anvil::Config.init }
6
6
 
7
- its('github.user') { should be_nil }
8
- its('github.token') { should be_nil }
9
-
10
- context 'with a config file', config: true do
11
- its('github.user') { should eq('dummy_user') }
12
- its('github.token') { should eq('dummy_token') }
13
- end
7
+ its('github.user') { is_expected.to eq('dummy_user') }
8
+ its('github.token') { is_expected.to eq('dummy_token') }
14
9
 
15
10
  context '.init_base_path' do
16
11
  before { Anvil::Config.send :init_base_path }
17
12
  subject { File }
18
13
 
19
- it { should be_directory(Anvil::Config.base_path) }
20
- it { should be_directory(Anvil::Config.base_tasks_path) }
21
- it { should be_exists(Anvil::Config.base_config_path) }
22
- it { should be_exists(Anvil::Config.base_projects_path) }
14
+ it { is_expected.to be_directory(Anvil::Config.base_path) }
15
+ it { is_expected.to be_directory(Anvil::Config.base_tasks_path) }
16
+ it { is_expected.to be_exists(Anvil::Config.base_config_path) }
17
+ it { is_expected.to be_exists(Anvil::Config.base_projects_path) }
23
18
  end
24
19
  end
@@ -25,7 +25,7 @@ describe Anvil::ExtensionsManager do
25
25
  let(:pwd) { '/home/user/src/project/' }
26
26
  context 'on a path managed by git' do
27
27
  before do
28
- Rugged::Repository.stub(:discover)
28
+ allow(Rugged::Repository).to receive(:discover)
29
29
  .and_return(double(path: "#{pwd}.git/"))
30
30
  end
31
31
 
@@ -37,7 +37,7 @@ describe Anvil::ExtensionsManager do
37
37
 
38
38
  context 'on a path not managed by git' do
39
39
  before do
40
- Rugged::Repository.stub(:discover)
40
+ allow(Rugged::Repository).to receive(:discover)
41
41
  .and_raise(Rugged::RepositoryError)
42
42
  end
43
43
 
@@ -7,7 +7,7 @@ describe Anvil::Parser do
7
7
 
8
8
  describe '#from' do
9
9
  before do
10
- task.stub(:parser_block).and_return(proc { 'opts' })
10
+ allow(task).to receive(:parser_block).and_return(proc { 'opts' })
11
11
  end
12
12
 
13
13
  it 'inherits parser block from another task' do
@@ -13,13 +13,13 @@ describe Anvil::Task::Naming do
13
13
  describe '.from_name' do
14
14
  context 'without a namespace' do
15
15
  it 'finds the task class' do
16
- klass.from_name('dummy').should eq(DummyTask)
16
+ expect(klass.from_name('dummy')).to eq(DummyTask)
17
17
  end
18
18
  end
19
19
 
20
20
  context 'with a namespace' do
21
21
  it 'finds the namespaced tasks class' do
22
- klass.from_name('foo:dummy').should eq(Foo::DummyTask)
22
+ expect(klass.from_name('foo:dummy')).to eq(Foo::DummyTask)
23
23
  end
24
24
  end
25
25
  end
@@ -33,7 +33,7 @@ describe Anvil::Task::Projects, fakefs: true do
33
33
  end
34
34
 
35
35
  describe '#on_project' do
36
- before { subject.stub(:git).and_return(double('git')) }
36
+ before { allow(subject).to receive(:git).and_return(double('git')) }
37
37
 
38
38
  it 'keeps the project changed inside the block' do
39
39
  subject.on_project project do
@@ -12,8 +12,8 @@ describe Anvil::Task do
12
12
 
13
13
  subject(:afters) { dummy_task.afters }
14
14
  it 'adds DummyBeforeTask to the after callbacks' do
15
- afters.first.should be_an_instance_of Anvil::Task::Callback
16
- afters.first.task.should be DummyAfterTask
15
+ expect(afters.first).to be_an_instance_of(Anvil::Task::Callback)
16
+ expect(afters.first.task).to be(DummyAfterTask)
17
17
  end
18
18
  end
19
19
 
@@ -21,7 +21,7 @@ describe Anvil::Task do
21
21
  before { dummy_task.class_eval { assure :dummy } }
22
22
 
23
23
  it 'adds DummyAssure to the assures' do
24
- dummy_task.assures.should include(assure)
24
+ expect(dummy_task.assures).to include(assure)
25
25
  end
26
26
  end
27
27
 
@@ -32,8 +32,8 @@ describe Anvil::Task do
32
32
 
33
33
  subject(:befores) { dummy_task.befores }
34
34
  it 'adds DummyBeforeTask to the before callbacks' do
35
- befores.first.should be_an_instance_of Anvil::Task::Callback
36
- befores.first.task.should be DummyBeforeTask
35
+ expect(befores.first).to be_an_instance_of(Anvil::Task::Callback)
36
+ expect(befores.first.task).to be(DummyBeforeTask)
37
37
  end
38
38
  end
39
39
 
@@ -47,31 +47,36 @@ describe Anvil::Task do
47
47
  subject { dummy_task.new }
48
48
 
49
49
  context 'with a passing assure' do
50
- before { dummy_task.stub(:assures).and_return([DummyAssure]) }
50
+ before do
51
+ allow(dummy_task).to receive(:assures).and_return([DummyAssure])
52
+ end
51
53
 
52
54
  it 'runs the callbacks and the task' do
53
- subject.should_receive(:run_before_callbacks)
54
- subject.should_receive(:run_after_callbacks)
55
- subject.should_receive(:run_task)
55
+ expect(subject).to receive(:run_before_callbacks)
56
+ expect(subject).to receive(:run_after_callbacks)
57
+ expect(subject).to receive(:run_task)
56
58
  subject.run
57
59
  end
58
60
  end
59
61
 
60
62
  context 'with a non passing assure' do
61
- before { dummy_task.stub(:assures).and_return([DummyFailedAssure]) }
63
+ before do
64
+ allow(dummy_task).to receive(:assures).and_return([DummyFailedAssure])
65
+ end
62
66
 
63
67
  it 'does not run the callbacks nor the task' do
64
- subject.should_not_receive(:run_before_callbacks)
65
- subject.should_not_receive(:run_after_callbacks)
66
- subject.should_not_receive(:run_task)
68
+ expect(subject).to_not receive(:run_before_callbacks)
69
+ expect(subject).to_not receive(:run_after_callbacks)
70
+ expect(subject).to_not receive(:run_task)
67
71
  subject.run
68
72
  end
69
73
  end
70
74
  end
71
75
 
72
76
  describe '.run' do
77
+ let(:task) { double run: true }
73
78
  it 'calls run in a instance of the task' do
74
- dummy_task.any_instance.should_receive(:run)
79
+ expect(described_class).to receive(:new).and_return(task)
75
80
  dummy_task.run(1, 2)
76
81
  end
77
82
  end
@@ -6,31 +6,31 @@ describe Anvil::Versioner do
6
6
 
7
7
  describe '#major!' do
8
8
  it 'bumps the major version and resets the others' do
9
- subject.major!.should == '2.0.0'
9
+ expect(subject.major!).to eq('2.0.0')
10
10
  end
11
11
  end
12
12
 
13
13
  describe '#minor!' do
14
14
  it 'bumps minor term and resets patch, pre and build' do
15
- subject.minor!.should == '1.3.0'
15
+ expect(subject.minor!).to eq('1.3.0')
16
16
  end
17
17
  end
18
18
 
19
19
  describe '#patch!' do
20
20
  it 'bumps the patch term and resets the pre and build' do
21
- subject.patch!.should == '1.2.4'
21
+ expect(subject.patch!).to eq('1.2.4')
22
22
  end
23
23
  end
24
24
 
25
25
  describe '#pre' do
26
26
  it 'bumps the pre-release version and resets the build' do
27
- subject.pre!.should == '1.2.3-alpha.2'
27
+ expect(subject.pre!).to eq('1.2.3-alpha.2')
28
28
  end
29
29
  end
30
30
 
31
31
  describe '#build!' do
32
32
  it 'bumps the build version' do
33
- subject.build!.should == '1.2.3-alpha.1+build.3'
33
+ expect(subject.build!).to eq('1.2.3-alpha.1+build.3')
34
34
  end
35
35
  end
36
36
 
@@ -49,7 +49,7 @@ describe Gem::BuildTask do
49
49
  let(:gem_file) { 'alfred.gem' }
50
50
 
51
51
  before do
52
- Anvil::Rubygems.stub(:build) do
52
+ allow(Anvil::Rubygems).to receive(:build) do
53
53
  FileUtils.touch('anvil-2.0.0.gem')
54
54
 
55
55
  output
@@ -59,11 +59,11 @@ describe Gem::BuildTask do
59
59
  it 'builds the gem' do
60
60
  subject.build_gem(gem_file)
61
61
 
62
- expect(File.exists?('pkg/anvil-2.0.0.gem')).to be_true
62
+ expect(File.exists?('pkg/anvil-2.0.0.gem')).to be_truthy
63
63
  end
64
64
 
65
65
  it 'returns the gem file path' do
66
- expect(subject.build_gem(gem_file)).to be_eql('/pkg/anvil-2.0.0.gem')
66
+ expect(subject.build_gem(gem_file)).to include('/pkg/anvil-2.0.0.gem')
67
67
  end
68
68
  end
69
69
 
@@ -7,11 +7,13 @@ describe Gem::BumpTask do
7
7
  subject { Gem::BumpTask.new 'major' }
8
8
 
9
9
  describe '#task' do
10
- before { subject.stub(:read_version).and_return('2.0.0') }
10
+ before { allow(subject).to receive(:read_version).and_return('2.0.0') }
11
11
 
12
12
  it 'bumps the version and writes it' do
13
13
  expect(subject).to receive(:prepare_repo).and_return(true)
14
- expect(subject).to receive(:write_version).and_return(true)
14
+ allow(subject).to receive(:write_version)
15
+ .with(instance_of(String))
16
+ .and_return(true)
15
17
 
16
18
  expect(subject.task).to eq('3.0.0')
17
19
  end
@@ -39,8 +41,8 @@ describe Gem::BumpTask do
39
41
  describe '#prepare_repo' do
40
42
  context 'on a clean repo' do
41
43
  before do
42
- subject.stub(:clean?).and_return(true)
43
- subject.stub(:git).and_return(double)
44
+ allow(subject).to receive(:clean?).and_return(true)
45
+ allow(subject).to receive(:git).and_return(double)
44
46
  end
45
47
 
46
48
  it 'pulls' do
@@ -51,7 +53,7 @@ describe Gem::BumpTask do
51
53
  end
52
54
 
53
55
  context 'on a dirty repo' do
54
- before { subject.stub(:clean?).and_return(false) }
56
+ before { allow(subject).to receive(:clean?).and_return(false) }
55
57
 
56
58
  it 'raises RepoNotClean' do
57
59
  expect do
@@ -10,12 +10,12 @@ describe Gem::ReleaseTask do
10
10
 
11
11
  describe '#task' do
12
12
  before do
13
- subject.stub(:bump).and_return(version)
14
- subject.stub(:build).and_return(gem_file)
13
+ allow(subject).to receive(:bump).and_return(version)
14
+ allow(subject).to receive(:build).and_return(gem_file)
15
15
  end
16
16
 
17
17
  it 'pushes the gem to rubygems' do
18
- subject.should_receive(:push).with(gem_file, version)
18
+ expect(subject).to receive(:push)
19
19
  end
20
20
 
21
21
  after { subject.task }
@@ -4,6 +4,7 @@ require 'fileutils'
4
4
 
5
5
  describe Projects::AddTask do
6
6
  let(:repo_url) { 'git@github.com:account/repo' }
7
+ before { Anvil::Config.send :init_base_path }
7
8
 
8
9
  subject { described_class.new('repo', 'account/repo') }
9
10
 
@@ -18,7 +19,7 @@ describe Projects::AddTask do
18
19
 
19
20
  describe '#clone_repo', config: true do
20
21
  it 'clones the repo with Git' do
21
- Git.should_receive(:clone)
22
+ expect(Git).to receive(:clone)
22
23
 
23
24
  subject.clone_repo(repo_url, 'repo')
24
25
  end
@@ -5,19 +5,20 @@
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
 
8
- require 'fakefs/spec_helpers'
8
+ require 'rspec/its'
9
9
  require 'anvil'
10
10
 
11
11
  begin
12
12
  require 'codeclimate-test-reporter'
13
13
  CodeClimate::TestReporter.start
14
- rescue LoadError; end
14
+ rescue LoadError
15
+ puts "Couldn't load the codeclimate test reporter"
16
+ end
15
17
 
16
- Dir["#{File.dirname(__FILE__)}/support/fixtures/**/*.rb"].each { |f| require f }
18
+ Dir["#{File.dirname(__FILE__)}/support/dummy_tasks/**/*.rb"].each { |f| require f }
17
19
  Dir["#{File.dirname(__FILE__)}/support/shared/**/*.rb"].each { |f| require f }
18
20
 
19
21
  RSpec.configure do |config|
20
- config.treat_symbols_as_metadata_keys_with_true_values = true
21
22
  config.run_all_when_everything_filtered = true
22
23
  config.filter_run :focus
23
24
 
@@ -26,7 +27,13 @@ RSpec.configure do |config|
26
27
  # the seed, which is printed after each run.
27
28
  # --seed 1234
28
29
  config.order = 'random'
29
- config.before(:all) do
30
- Anvil.module_eval { @logger = Logger.new(nil) }
30
+ config.before(:suite) { Anvil.module_eval { @logger = Logger.new(nil) } }
31
+ config.before do
32
+ FileUtils.rm_rf ConfigMock.base_path
33
+ FileUtils.mkdir_p ConfigMock.base_path
34
+ FileUtils.cp ConfigMock.config_file,
35
+ ConfigMock.base_path
31
36
  end
37
+
38
+ config.after { FileUtils.rm_rf ConfigMock.base_path }
32
39
  end
@@ -1,2 +1,2 @@
1
- github.user 'dummy_user'
1
+ github.user 'dummy_user'
2
2
  github.token 'dummy_token'
@@ -0,0 +1,17 @@
1
+ # Mocks the anvil config and folder for the specs so that it uses a
2
+ # sandbox instead of the user's one
3
+ module ConfigMock
4
+ def self.base_path
5
+ File.expand_path('../dot_anvil', File.dirname(__FILE__))
6
+ end
7
+
8
+ def self.config_file
9
+ File.expand_path('../fixtures/config.rb', File.dirname(__FILE__))
10
+ end
11
+ end
12
+
13
+ Anvil::Config::ClassMethods.module_eval do
14
+ def base_path
15
+ ConfigMock.base_path
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anvil-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fran Casas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-09 00:00:00.000000000 Z
12
+ date: 2015-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: git
@@ -115,28 +115,28 @@ dependencies:
115
115
  requirements:
116
116
  - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '2.14'
118
+ version: '3.2'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '2.14'
125
+ version: '3.2'
126
126
  - !ruby/object:Gem::Dependency
127
- name: fakefs
127
+ name: rspec-its
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - "~>"
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: '0.5'
132
+ version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - "~>"
137
+ - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: '0.5'
139
+ version: '0'
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: rubocop
142
142
  requirement: !ruby/object:Gem::Requirement
@@ -175,6 +175,7 @@ files:
175
175
  - lib/anvil/config.rb
176
176
  - lib/anvil/config/class_methods.rb
177
177
  - lib/anvil/extensions_manager.rb
178
+ - lib/anvil/options_detector.rb
178
179
  - lib/anvil/parser.rb
179
180
  - lib/anvil/rubygems.rb
180
181
  - lib/anvil/task.rb
@@ -213,15 +214,14 @@ files:
213
214
  - spec/lib/tasks/projects/add_task_spec.rb
214
215
  - spec/lib/tasks/projects/list_task_spec.rb
215
216
  - spec/spec_helper.rb
216
- - spec/support/dot_anvil/config.rb
217
- - spec/support/fixtures/dummy_after_task.rb
218
- - spec/support/fixtures/dummy_assure.rb
219
- - spec/support/fixtures/dummy_before_task.rb
220
- - spec/support/fixtures/dummy_failed_assure.rb
221
- - spec/support/fixtures/dummy_task.rb
222
- - spec/support/fixtures/foo/dummy_task.rb
223
- - spec/support/shared/config_context.rb
224
- - spec/support/shared/fake_fs_context.rb
217
+ - spec/support/dummy_tasks/dummy_after_task.rb
218
+ - spec/support/dummy_tasks/dummy_assure.rb
219
+ - spec/support/dummy_tasks/dummy_before_task.rb
220
+ - spec/support/dummy_tasks/dummy_failed_assure.rb
221
+ - spec/support/dummy_tasks/dummy_task.rb
222
+ - spec/support/dummy_tasks/foo/dummy_task.rb
223
+ - spec/support/fixtures/config.rb
224
+ - spec/support/shared/config_mock.rb
225
225
  homepage: http://github.com/anvil-src/anvil-core
226
226
  licenses:
227
227
  - MIT
@@ -242,37 +242,36 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
242
  version: 2.1.0
243
243
  requirements: []
244
244
  rubyforge_project:
245
- rubygems_version: 2.3.0
245
+ rubygems_version: 2.4.3
246
246
  signing_key:
247
247
  specification_version: 4
248
248
  summary: Anvil is a tool for building tools. A tool that a real craftsmen uses to
249
249
  build its tools.
250
250
  test_files:
251
251
  - spec/spec_helper.rb
252
- - spec/support/fixtures/foo/dummy_task.rb
253
- - spec/support/fixtures/dummy_after_task.rb
254
- - spec/support/fixtures/dummy_failed_assure.rb
255
- - spec/support/fixtures/dummy_task.rb
256
- - spec/support/fixtures/dummy_assure.rb
257
- - spec/support/fixtures/dummy_before_task.rb
258
- - spec/support/dot_anvil/config.rb
259
- - spec/support/shared/config_context.rb
260
- - spec/support/shared/fake_fs_context.rb
261
- - spec/lib/anvil/assure_spec.rb
252
+ - spec/lib/tasks/projects/add_task_spec.rb
253
+ - spec/lib/tasks/projects/list_task_spec.rb
254
+ - spec/lib/tasks/gem/release_task_spec.rb
255
+ - spec/lib/tasks/gem/build_task_spec.rb
256
+ - spec/lib/tasks/gem/bump_task_spec.rb
257
+ - spec/lib/anvil/config_spec.rb
262
258
  - spec/lib/anvil/cli_spec.rb
263
259
  - spec/lib/anvil/task_spec.rb
264
- - spec/lib/anvil/config_spec.rb
265
- - spec/lib/anvil/assures/file_assure_spec.rb
260
+ - spec/lib/anvil/extensions_manager_spec.rb
266
261
  - spec/lib/anvil/assures/directory_assure_spec.rb
267
- - spec/lib/anvil/versioner_spec.rb
262
+ - spec/lib/anvil/assures/file_assure_spec.rb
268
263
  - spec/lib/anvil/parser_spec.rb
264
+ - spec/lib/anvil/versioner_spec.rb
265
+ - spec/lib/anvil/task/projects_spec.rb
269
266
  - spec/lib/anvil/task/callback_spec.rb
270
267
  - spec/lib/anvil/task/naming_spec.rb
271
- - spec/lib/anvil/task/projects_spec.rb
272
268
  - spec/lib/anvil/task/options_spec.rb
273
- - spec/lib/anvil/extensions_manager_spec.rb
274
- - spec/lib/tasks/gem/build_task_spec.rb
275
- - spec/lib/tasks/gem/bump_task_spec.rb
276
- - spec/lib/tasks/gem/release_task_spec.rb
277
- - spec/lib/tasks/projects/list_task_spec.rb
278
- - spec/lib/tasks/projects/add_task_spec.rb
269
+ - spec/lib/anvil/assure_spec.rb
270
+ - spec/support/dummy_tasks/dummy_failed_assure.rb
271
+ - spec/support/dummy_tasks/dummy_before_task.rb
272
+ - spec/support/dummy_tasks/foo/dummy_task.rb
273
+ - spec/support/dummy_tasks/dummy_task.rb
274
+ - spec/support/dummy_tasks/dummy_after_task.rb
275
+ - spec/support/dummy_tasks/dummy_assure.rb
276
+ - spec/support/fixtures/config.rb
277
+ - spec/support/shared/config_mock.rb
@@ -1,12 +0,0 @@
1
- shared_context 'init anvil config', config: true do
2
- include_context 'with FakeFS'
3
-
4
- let(:test_config_path) do
5
- File.expand_path('./spec/support/dot_anvil', File.dirname(__FILE__))
6
- end
7
-
8
- before do
9
- Anvil::Config.stub(:base_path).and_return(test_config_path)
10
- Anvil::Config.init
11
- end
12
- end
@@ -1,4 +0,0 @@
1
- shared_context 'with FakeFS', fakefs: true do
2
- before { FakeFS.activate! }
3
- after { FakeFS.deactivate! }
4
- end