rspec-rake 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1192ef82b6d2f2ed8d3f53986fc3c4ad08d61f16
4
+ data.tar.gz: abc1cf70bf660e96a478e140a7362f8444b5bcba
5
+ SHA512:
6
+ metadata.gz: 5908679322a3a5cc18e17baa0edc580f1049726ac7c0132da5f7e0e431ef5a7d024ddea3e867c2fb309f52e9ee32af5124ba099d35622d3c51210c641e118cdb
7
+ data.tar.gz: b995a437c9346f01cbbf4fc9d9e4d1680d3660fbeeb87620c79c83aebfc938b3790d74e15d63a5edaac7cbb5edb3917f2639bf90528226aaec0b7797a8d44341
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-rake.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Stas SUȘCOV
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ # RSpec Rake Support
2
+
3
+ You can test you Rake files like you test your Rails app.
4
+
5
+ This gem adds an example group and configures RSpec so we can write tests for our Rake tasks easily.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rspec-rake'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rspec-rake
20
+
21
+ ## Usage
22
+
23
+ Require `rspec/rake` in your `spec_helper.rb`
24
+
25
+ ```ruby
26
+ require 'rspec/rake'
27
+ ```
28
+
29
+ And start writing tests in your `spec/tasks` directory.
30
+
31
+ Normally `RSpec::Rake` will detect a **task** test and will try loading it from your `lib/tasks/*.rake` directory.
32
+
33
+ You can manually specify the rake file location and file name by using metadata:
34
+
35
+ ```ruby
36
+ describe 'task:subtask', :rakefile => 'my_task' do
37
+ # Spot the :rakefile metadata value
38
+ # This will tell `RSpec::Test` to load `lib/tasks/my_task.rake`
39
+ end
40
+ ```
41
+
42
+ ```ruby
43
+ describe 'task:subtask', :rakefile => 'my_task', :tasks_path => 'lib/capistrano/tasks' do
44
+ # Same with the :tasks_path metadata value
45
+ # This will tell `RSpec::Test` to load `lib/capistrano/task/my_task.rake`
46
+ end
47
+ ```
48
+
49
+ ### Limitations
50
+
51
+ Due to how `Rake::Application#rake_require` works, only files with `.rake` extension can be tests.
52
+
53
+ ## Plagiarism alert
54
+
55
+ My tentative to provide RSpec support for testing Rake tasks in a convenient and idiomatic way is not new.
56
+ Previously [Thoughtbot](http://robots.thoughtbot.com/test-rake-tasks-like-a-boss) and [Tyler Hunt](http://devoh.com/blog/2010/11/testing-rake-tasks-with-rspec) wrote about this.
57
+
58
+ Although I picked a different approach to handle the same problem, it is pretty much the same solution. All I did is tried to put it all together and provide it the way you see it now.
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it ( http://github.com/stas/rspec-rake/fork )
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ require 'rspec/rake/version'
2
+ require 'rspec/rake/example_group'
3
+
4
+ RSpec.configure do |config|
5
+ config.include RSpec::Rake::ExampleGroup,
6
+ :type => :task,
7
+ :example_group => lambda { |example_group, metadata|
8
+ metadata[:type].nil? && %r{spec/tasks}.match(example_group[:file_path])
9
+ }
10
+ end
@@ -0,0 +1,33 @@
1
+ require 'rake'
2
+
3
+ module RSpec::Rake
4
+
5
+ module ExampleGroup
6
+
7
+ def self.included(base)
8
+ base.instance_eval do
9
+
10
+ metadata[:type] = :task
11
+ metadata[:tasks_path] ||= File.join('../', 'lib', 'tasks')
12
+ metadata[:rakefile] ||= nil
13
+
14
+ subject(:task) { Rake.application[self.class.top_level_description] }
15
+
16
+ before(:all) do
17
+ metadata = self.class.metadata
18
+ task_name = self.class.top_level_description
19
+
20
+ rakefile = metadata[:rakefile] || task_name.split(':').first
21
+ task_path = File.join(metadata[:tasks_path], rakefile)
22
+
23
+ Rake.application = Rake::Application.new
24
+ # We are sending an empty list of loaded files
25
+ # in order to force loading of existing files
26
+ Rake.application.rake_require(task_path, $LOAD_PATH, [])
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ module Rspec
2
+ module Rake
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/rake/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-rake"
8
+ spec.version = Rspec::Rake::VERSION
9
+ spec.authors = ["Stas SUȘCOV"]
10
+ spec.email = ["stas@net.utcluj.ro"]
11
+ spec.summary = %q{Test Rake tasks with RSpec.}
12
+ spec.description = %q{RSpec support for testing Rake tasks.}
13
+ spec.homepage = "https://github.com/stas/rspec-rake"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rake"
22
+ spec.add_dependency "rspec-core"
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,9 @@
1
+ namespace :example do
2
+ namespace :subexample do
3
+ task :task do
4
+ Kernel.puts 'OK'
5
+ end
6
+ end
7
+ end
8
+
9
+ task :default => 'example:subexample:task'
@@ -0,0 +1,19 @@
1
+ require 'rspec/rake'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'default', :rakefile => 'example', :tasks_path => './fixtures' do
4
+ it 'task lists another task as the prerequisite' do
5
+ expect(task.prerequisites).to include('example:subexample:task')
6
+ end
7
+
8
+ it 'task calls `puts`' do
9
+ expect(Kernel).to receive(:puts).with('OK')
10
+ task.invoke
11
+ end
12
+ end
13
+
14
+ describe 'example:subexample:task', :tasks_path => 'fixtures' do
15
+ it 'has no prerequisites' do
16
+ expect(task.prerequisites).to be_empty
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-rake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stas SUȘCOV
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-02 00:00:00.000000000 Z
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: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: RSpec support for testing Rake tasks.
70
+ email:
71
+ - stas@net.utcluj.ro
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/rspec/rake.rb
83
+ - lib/rspec/rake/example_group.rb
84
+ - lib/rspec/rake/version.rb
85
+ - rspec-rake.gemspec
86
+ - spec/fixtures/example.rake
87
+ - spec/spec_helper.rb
88
+ - spec/tasks/rake_task_spec.rb
89
+ homepage: https://github.com/stas/rspec-rake
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.0
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Test Rake tasks with RSpec.
113
+ test_files:
114
+ - spec/fixtures/example.rake
115
+ - spec/spec_helper.rb
116
+ - spec/tasks/rake_task_spec.rb