rake_shared_context 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5521673b9b6201456c829e516c25bd616f3b092d
4
- data.tar.gz: 1bc74c362473e4ad4da113bbac06c0304bc6bdc8
3
+ metadata.gz: 2ee7b1d5e1b0c45048706fe8296c9c6d29f13d16
4
+ data.tar.gz: e7eaf7bc32c862e1ba8dc7eba1689094a3766820
5
5
  SHA512:
6
- metadata.gz: d7c1cfdc3919cec4232493102fd8de052294da9e7702064350dcdf4fe548faa90e015899edbb3a3f71b42fa82b6c8c2a5771faac948bdb3903ff238757549ca0
7
- data.tar.gz: 5077431efc9192f621ce87858d7745b38d838e93748309386d164395dc7c5e48d4d9e26b1272ec8b6b26da54afda44774c1938103f51a30374e070c803d5f8e6
6
+ metadata.gz: 76b730d776b8cb5f069f9c36ff01d6cc0d288663e93a26ec8b4129729377fd868d0a9e5a8bacfd40e704aa33cc38029a47ee61d3ccc09a2f76e3d1912f68fa8d
7
+ data.tar.gz: 7e93a4c7555070524e924a3d310ad5dc33175fe8e6853742a23eb02816b550d3977034c78624205345096626baeaceda5b101f91ed77227c5afd534229a312ca
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ vendor/bundle
19
+ bin
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # RakeSharedContext
2
2
 
3
+ [![Build Status](https://travis-ci.org/willnet/gimei.png)](https://travis-ci.org/willnet/rake_shared_context)
4
+ [![Gem Version](https://badge.fury.io/rb/rake_shared_context.png)](http://badge.fury.io/rb/rake_shared_context)
5
+
3
6
  shared_context for rake tasks.
4
7
 
5
8
  This gem is inspired by [this post](http://robots.thoughtbot.com/post/11957424161/test-rake-tasks-like-a-boss).
@@ -39,7 +42,7 @@ Then you can write following.
39
42
  # spec/lib/tasks/reports_rake_spec.rb
40
43
 
41
44
  require 'spec_helper'
42
- describe "reports:genereate" do
45
+ describe "reports:generate" do
43
46
  include_context "rake"
44
47
 
45
48
  its(:prerequisites) { should include("environment") }
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ Bundler.setup
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new("spec")
7
+ task :default => :spec
@@ -1,3 +1,3 @@
1
- module RakeSharedContext
2
- VERSION = "0.0.2"
1
+ class RakeSharedContext
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,5 +1,37 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require "rake_shared_context/version"
2
3
  require "rake"
4
+ require "pathname"
5
+
6
+ class RakeSharedContext
7
+ class << self
8
+ def root_dir
9
+ return @root_dir if @root_dir
10
+
11
+ if defined? Rails
12
+ Rails.root
13
+ elsif defined? Padrino
14
+ Pathname.new(Padrino.root)
15
+ else
16
+ Pathname.pwd
17
+ end
18
+ end
19
+
20
+ def root_dir=(dir)
21
+ @root_dir = Pathname.new(dir)
22
+ end
23
+
24
+ def rake_dir
25
+ return @rake_dir if @rake_dir
26
+
27
+ root_dir.join('lib', 'tasks')
28
+ end
29
+
30
+ def rake_dir=(dir)
31
+ @rake_dir = Pathname.new(dir)
32
+ end
33
+ end
34
+ end
3
35
 
4
36
  begin
5
37
  require "rspec/core"
@@ -11,10 +43,13 @@ begin
11
43
  before do
12
44
  loaded_files = []
13
45
  Rake.application = rake
14
- Dir::glob("lib/tasks/*.rake").each do |task|
15
- Rake.application.rake_require(task.sub(/.rake$/,''), [Rails.root.to_s], loaded_files)
46
+ rake_dir = RakeSharedContext.rake_dir
47
+
48
+ Dir.glob(rake_dir.join("*.rake")).each do |task|
49
+ filename_without_ext = File.basename(task.sub(/.rake$/, ''))
50
+ Rake.application.rake_require(filename_without_ext, [rake_dir.to_s], loaded_files)
16
51
  end
17
-
52
+
18
53
  Rake::Task.define_task(:environment)
19
54
  end
20
55
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["netwillnet@gmail.com"]
7
7
  gem.description = %q{shared_context for rake task}
8
8
  gem.summary = %q{shared_context for rake task}
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/willnet/rake_shared_context"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -14,5 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "rake_shared_context"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = RakeSharedContext::VERSION
17
+ gem.add_development_dependency "rake"
17
18
  gem.add_development_dependency "rspec"
19
+ gem.add_development_dependency "pry"
18
20
  end
@@ -0,0 +1,5 @@
1
+ class ReportGenerator
2
+ def self.generate
3
+ # do nothing
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ namespace :reports do
2
+ desc "Generate report"
3
+
4
+ task :generate => :environment do
5
+ ReportGenerator.generate
6
+ end
7
+
8
+ task :environment do
9
+ # do nothing
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ describe RakeSharedContext do
2
+ describe '.root_dir' do
3
+ after do
4
+ RakeSharedContext.instance_variable_set(:@root_dir, nil)
5
+ end
6
+
7
+ context '`.root_dir=` was executed before' do
8
+ it 'should return the root_dir' do
9
+ RakeSharedContext.root_dir = 'foo'
10
+ expect(RakeSharedContext.root_dir).to eq Pathname.new('foo')
11
+ end
12
+ end
13
+
14
+ context '`.root_dir=` was not executed before' do
15
+ context 'Rails.root is defined' do
16
+ before { Rails = double('Rails', root: 'rails') }
17
+ after { Object.send(:remove_const, :Rails) }
18
+
19
+ it 'should return `Rails.root`' do
20
+ expect(RakeSharedContext.root_dir).to eq 'rails'
21
+ end
22
+ end
23
+
24
+ context 'Padrino.root is defined' do
25
+ before { Padrino = double('Padrino', root: 'padrino') }
26
+ after { Object.send(:remove_const, :Padrino) }
27
+
28
+ it 'should return `Padrino.root`' do
29
+ expect(RakeSharedContext.root_dir).to eq Pathname.new('padrino')
30
+ end
31
+ end
32
+
33
+ context 'nothing is defined' do
34
+ it 'should return current directory' do
35
+ expect(RakeSharedContext.root_dir).to eq Pathname.pwd
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
data/spec/rake_spec.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'lib/report_generator'
3
+
4
+ describe "reports:generate" do
5
+ before do
6
+ RakeSharedContext.root_dir = File.expand_path('..', __FILE__)
7
+ end
8
+
9
+ include_context "rake"
10
+
11
+ its(:prerequisites) { should include("environment") }
12
+
13
+ it "generates the report" do
14
+ ReportGenerator.should_receive(:generate)
15
+ subject.invoke
16
+ end
17
+ end
18
+
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'rake_shared_context'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake_shared_context
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - willnet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-05 00:00:00.000000000 Z
11
+ date: 2013-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - '>='
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  description: shared_context for rake task
28
56
  email:
29
57
  - netwillnet@gmail.com
@@ -32,6 +60,7 @@ extensions: []
32
60
  extra_rdoc_files: []
33
61
  files:
34
62
  - .gitignore
63
+ - .travis.yml
35
64
  - CHANGELOG.md
36
65
  - Gemfile
37
66
  - LICENSE
@@ -40,7 +69,12 @@ files:
40
69
  - lib/rake_shared_context.rb
41
70
  - lib/rake_shared_context/version.rb
42
71
  - rake_shared_context.gemspec
43
- homepage: ''
72
+ - spec/lib/report_generator.rb
73
+ - spec/lib/tasks/reports.rake
74
+ - spec/paths_spec.rb
75
+ - spec/rake_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: https://github.com/willnet/rake_shared_context
44
78
  licenses: []
45
79
  metadata: {}
46
80
  post_install_message:
@@ -59,8 +93,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
93
  version: '0'
60
94
  requirements: []
61
95
  rubyforge_project:
62
- rubygems_version: 2.0.0
96
+ rubygems_version: 2.0.3
63
97
  signing_key:
64
98
  specification_version: 4
65
99
  summary: shared_context for rake task
66
- test_files: []
100
+ test_files:
101
+ - spec/lib/report_generator.rb
102
+ - spec/lib/tasks/reports.rake
103
+ - spec/paths_spec.rb
104
+ - spec/rake_spec.rb
105
+ - spec/spec_helper.rb
106
+ has_rdoc: