cucumber_rake_runner 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,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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cucumber_rake_runner.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Stuart Ingram
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,55 @@
1
+ # CucumberRakeRunner
2
+
3
+ Cucumber helper to run rake tasks in the current process, capturing properties to assert tests against
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cucumber_rake_runner'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cucumber_rake_runner
18
+
19
+ ## Problem
20
+
21
+ Sometimes there is a need to test your rake tasks. Typically this is done by a system call such as
22
+
23
+ @output = `rake some:amazing:task`
24
+
25
+ Sometimes this is desirable, at other times, in particular when using Jruby it is not. For each execution of the above a new JVM must spin up costing significant delays to test turnaround time.
26
+
27
+ The solution is to run the task inline to the cucumber process via Rake's invoke command. This gem provides a handy dandy solution to get the above functionality and more while running the rake task inline to the current process.
28
+
29
+ ## Usage
30
+
31
+ Simply incorportate the following call appropriately in your step definitions
32
+
33
+ @rake_output = run_rake_task(task_name, arg1, arg2, ... )
34
+
35
+ This will run the rake tasks with the specified parameters. If the rake task does not take parameters only the task_name is required.
36
+
37
+ The returned obect from this call is an OpenStruct with the following properties
38
+
39
+ 1. stdout - All output generated by the task sent to stdout
40
+ 2. stderr - All output generated by the task sent to stderr
41
+ 3. time - Time taken to execute rake task.
42
+
43
+ for example
44
+
45
+ @rake_output.stdout.include? 'Some expected output from task'
46
+
47
+ See the features and step definitions in this gem for example usage.
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ namespace :cucumber_rake_runner do
4
+
5
+ desc "STDOUT test"
6
+ task :stdout_test do
7
+ puts "String expected to be sent to STDOUT"
8
+ end
9
+
10
+ desc "Time test"
11
+ task :time_test, :delay do |t, args|
12
+ delay = args[:delay] || 1
13
+ sleep(delay.to_f)
14
+ end
15
+
16
+ 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 'cucumber_rake_runner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cucumber_rake_runner"
8
+ spec.version = CucumberRakeRunner::VERSION
9
+ spec.authors = ["Stuart Ingram"]
10
+ spec.email = ["ingrams2@upmc.com"]
11
+ spec.description = %q{Cucumber helper to run rake tasks in the current process, capturing properties to assert tests against }
12
+ spec.summary = %q{Cucumber helper to run rake tasks}
13
+ spec.homepage = "https://github.com/singram/cucumber_rake_runner"
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 "cucumber", "~> 1.3"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,16 @@
1
+ Feature:
2
+ As a tester of rake tasks
3
+ I want to execute rake tasks inline to the current process
4
+ And to capture properties about the rake task to test against
5
+
6
+ Scenario: Testing the capture of STDOUT
7
+ When I run the rake task 'cucumber_rake_runner:stdout_test'
8
+ Then the contents of STDOUT should contain 'String expected to be sent to STDOUT'
9
+
10
+ Scenario: Testing the capture of timing with default duration of 1 second
11
+ When I run the rake task 'cucumber_rake_runner:time_test'
12
+ Then the task should have taken '1' seconds
13
+
14
+ Scenario: Testing the capture of timing with non default duration (2 seconds)
15
+ When I run the rake task 'cucumber_rake_runner:time_test' with '2' as parameters
16
+ Then the task should have taken '2' seconds
@@ -0,0 +1,17 @@
1
+ When /^I run the rake task '(.+?)' with '(.*?)' as parameters$/ do |task_name, params|
2
+ args = params.split(',')
3
+ @rake_output = run_rake_task(task_name, *args)
4
+ end
5
+
6
+ When /^I run the rake task '(.+?)'$/ do |task_name|
7
+ @rake_output = run_rake_task(task_name)
8
+ end
9
+
10
+
11
+ Then /^the contents of STDOUT should contain '(.*?)'$/ do |expected_content|
12
+ @rake_output.stdout.include? expected_content
13
+ end
14
+
15
+ Then /^the task should have taken '(\d+?)' seconds$/ do |expected_time|
16
+ @rake_output.time.to_i == expected_time.to_i
17
+ end
@@ -0,0 +1,25 @@
1
+ require "cucumber_rake_runner/version"
2
+ require "cucumber_rake_runner/io_capture"
3
+ require "cucumber_rake_runner/rake_runner"
4
+
5
+ require 'rake'
6
+ require 'ostruct'
7
+ require 'benchmark'
8
+ require 'cucumber'
9
+
10
+ module CucumberRakeRunner
11
+
12
+ def run_rake_task(task_name, *args)
13
+ @stderr = IoCapture.stderr do
14
+ @stdout = IoCapture.stdout do
15
+ @time = Benchmark.realtime do
16
+ RakeRunner.invoke(task_name,*args)
17
+ end
18
+ end
19
+ end
20
+ OpenStruct.new( time: @time, stdout: @stdout, stderr: @stderr)
21
+ end
22
+
23
+ end
24
+
25
+ World(CucumberRakeRunner)
@@ -0,0 +1,27 @@
1
+ class IoCapture
2
+
3
+ def self.stdout
4
+ temp_stdout_buffer = StringIO.new
5
+ begin
6
+ old_stdout = $stdout
7
+ $stdout = temp_stdout_buffer
8
+ yield
9
+ ensure
10
+ $stdout = old_stdout
11
+ end
12
+ temp_stdout_buffer.string
13
+ end
14
+
15
+ def self.stderr
16
+ temp_stderr_buffer = StringIO.new
17
+ begin
18
+ old_stderr = $stderr
19
+ $stderr = temp_stderr_buffer
20
+ yield
21
+ ensure
22
+ $stderr = old_stderr
23
+ end
24
+ temp_stderr_buffer.string
25
+ end
26
+
27
+ end
@@ -0,0 +1,18 @@
1
+ class RakeRunner
2
+
3
+ def self.invoke(task_name, *args)
4
+ RakeRunner.rake_application[task_name].invoke(*args)
5
+ RakeRunner.rake_application[task_name].reenable
6
+ end
7
+
8
+ def self.rake_application
9
+ @rake_application ||= Rake.application.tap do |app|
10
+ ARGV.clear # Necessary to remove command line parameters built
11
+ # into jruby which are then parsed by the setup of the Rake
12
+ # application object
13
+ app.handle_options
14
+ app.load_rakefile
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,3 @@
1
+ module CucumberRakeRunner
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber_rake_runner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stuart Ingram
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: cucumber
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
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'
78
+ description: ! 'Cucumber helper to run rake tasks in the current process, capturing
79
+ properties to assert tests against '
80
+ email:
81
+ - ingrams2@upmc.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - cucumber_rake_runner.gemspec
92
+ - features/rake_runner.feature
93
+ - features/step_definitions/rake_steps.rb
94
+ - lib/cucumber_rake_runner.rb
95
+ - lib/cucumber_rake_runner/io_capture.rb
96
+ - lib/cucumber_rake_runner/rake_runner.rb
97
+ - lib/cucumber_rake_runner/version.rb
98
+ homepage: https://github.com/singram/cucumber_rake_runner
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.24
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Cucumber helper to run rake tasks
123
+ test_files:
124
+ - features/rake_runner.feature
125
+ - features/step_definitions/rake_steps.rb