cucumber-value 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ pkg/*
3
+ coverage
4
+ doc
5
+ .yardoc
6
+ .idea
7
+ tmp
8
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 1.9.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.0.1
2
+
3
+ * Random bunch of stuff hacked together on top of Cucumber.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'cucumber' do
2
+ watch(%r{^features/.+\.feature$})
3
+ watch(%r{^features/support/.+$}) { 'features' }
4
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
5
+ end
6
+ guard 'rspec', :version => 2, :bundler => false do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (C) 2011 by Colin Humphreys
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Cucumber-Value
2
+
3
+ [![Build Status](https://secure.travis-ci.org/hatofmonkeys/cucumber-value.png)](http://travis-ci.org/hatofmonkeys/cucumber-value)
4
+
5
+ Cucumber-value aims to bring Value-Driven Development to Cucumber.
6
+
7
+ See the [blog post](http://blog.hatofmonkeys.com/blog/2011/11/06/automating-value/) for details on the idea.
8
+
9
+ This is little more than a demo of the idea at the moment, I hope to make it useful in the near future.
10
+
11
+ ## Demo from features
12
+
13
+ bundle install
14
+ bundle exec rake
15
+
16
+ Requires Ruby >= 1.9.2 to pass the specs.
17
+
18
+ ## Usage
19
+
20
+ Add the gem to your project's Gemfile. Use it like the demo additions application in the supplied features. Wonder why it's not very useful at this stage. Fork the git repository, make it better, issue a pull request. Relax.
21
+
22
+ ## Contributing
23
+
24
+ Please, please, please fork this, improve it, and issue a pull request. You know you want to.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'cucumber'
4
+ require 'cucumber/rake/task'
5
+ require 'rspec/core/rake_task'
6
+ require 'yard'
7
+ task :default => [:install, :spec, :features]
8
+
9
+ Bundler.setup
10
+ Bundler::GemHelper.install_tasks
11
+
12
+ Cucumber::Rake::Task.new(:features) do |t|
13
+ t.cucumber_opts = "features --format pretty"
14
+ end
15
+
16
+ RSpec::Core::RakeTask.new
17
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "cucumber-value"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Colin Humphreys"]
8
+ s.homepage = "https://github.com/hatofmonkeys/cucumber-value"
9
+ s.summary = "#{s.name}-#{s.version}"
10
+ s.description = "Assert the value of Cucumber features"
11
+ s.license = 'MIT'
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_path = "lib"
16
+
17
+ s.add_development_dependency "rspec"
18
+ s.add_development_dependency "cucumber"
19
+ s.add_development_dependency "yard"
20
+ s.add_development_dependency "simplecov"
21
+ s.add_development_dependency "guard"
22
+ s.add_development_dependency "guard-cucumber"
23
+ s.add_development_dependency "guard-rspec"
24
+ s.add_development_dependency "rake"
25
+ s.add_development_dependency "aruba"
26
+ s.add_runtime_dependency "cucumber"
27
+ end
@@ -0,0 +1,120 @@
1
+ Given /^I have set up the environment with cucumber\-value support$/ do
2
+ steps %Q{
3
+ When I append to "Gemfile" with:
4
+ """
5
+ gem "cucumber-value", :group => :test, :path => "../.."
6
+ gem "rspec", :group => :test
7
+
8
+ """
9
+ And I append to "features/support/env.rb" with:
10
+ """
11
+ require 'cucumber/value'
12
+ require 'rspec'
13
+
14
+ """
15
+ }
16
+ end
17
+
18
+ Given /^I have set up the addition feature$/ do
19
+ steps %Q{
20
+ When I write to "features/addition.feature" with:
21
+ """
22
+ @testable-value
23
+ Feature: Addition
24
+ In order to make 0 silly mistakes
25
+ As a math idiot
26
+ I want to be told the sum of two numbers
27
+
28
+ Scenario: Add two numbers
29
+ Given I have entered 50 into the calculator
30
+ And I have entered 70 into the calculator
31
+ When I press add
32
+ Then the result should be 120 on the screen
33
+
34
+ """
35
+ And I write to "features/step_definitions/addition_steps.rb" with:
36
+ """
37
+ Given /I have entered (.*) into the calculator/ do |n|
38
+ @calculator ||= Calculator.new
39
+ @calculator.push(n.to_i)
40
+ end
41
+
42
+ When /I press add/ do
43
+ @calculator.add
44
+ end
45
+
46
+ Then /the result should be (.*) on the screen/ do |n|
47
+ @calculator.screen.should == n
48
+ end
49
+
50
+ """
51
+ }
52
+ end
53
+
54
+ Given /^I have set up the working calculator with metrics$/ do
55
+ steps %Q{
56
+ When I append to "lib/calculator.rb" with:
57
+ """
58
+ class Calculator
59
+ def initialize
60
+ @screen = 0
61
+ end
62
+ def push(n)
63
+ @args ||= []
64
+ @args << n
65
+ end
66
+ def add
67
+ @screen = generate_answer
68
+ metric = @screen == @args[0] + @args[1] ? "CORRECT" : "INCORRECT"
69
+ File.open("metrics.txt", 'a') {|f| f.puts(metric) }
70
+ end
71
+ def screen
72
+ @screen.to_s
73
+ end
74
+ def generate_answer
75
+ @args.inject(0){|sum,item| sum + item}
76
+ end
77
+ end
78
+
79
+ """
80
+ And I append to "features/support/env.rb" with:
81
+ """
82
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
83
+ require 'calculator'
84
+
85
+ """
86
+ }
87
+ end
88
+
89
+ Given /^I have set up the broken calculator with metrics$/ do
90
+ steps %Q{
91
+ Given I have set up the working calculator with metrics
92
+ And I append to "lib/calculator.rb" with:
93
+ """
94
+ class Calculator
95
+ def generate_answer
96
+ 120
97
+ end
98
+ end
99
+
100
+ """
101
+ }
102
+ end
103
+
104
+
105
+ Given /^I have run some sample additions$/ do
106
+ steps %Q{
107
+ When I append to "sample-additions.rb" with:
108
+ """
109
+ load "lib/calculator.rb"
110
+ (1..5).to_a.each_with_index do |i,k|
111
+ calc = Calculator.new
112
+ calc.push i
113
+ calc.push k
114
+ calc.add
115
+ end
116
+
117
+ """
118
+ And I run `ruby sample-additions.rb`
119
+ }
120
+ end
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'simplecov'
3
+ require 'aruba/cucumber'
4
+
5
+ Before do
6
+ @aruba_timeout_seconds = 30
7
+ unset_bundler_env_vars
8
+ end
9
+
10
+ SimpleCov.start
@@ -0,0 +1,64 @@
1
+ Feature: test value
2
+ In order to test the value of Cucumber features
3
+ As a user of cucumber-value
4
+ I want cucumber-value to be able to test for value
5
+
6
+ Scenario: testable value tagging
7
+ Given I have set up the environment with cucumber-value support
8
+ And I have set up the addition feature
9
+ When I run `bundle exec cucumber features/addition.feature`
10
+ Then the stdout should contain:
11
+ """
12
+ Testable value : make 0 silly mistakes
13
+ """
14
+
15
+ Scenario: executing value tests
16
+ Given I have set up the environment with cucumber-value support
17
+ And I have set up the addition feature
18
+ And I write to "features/step_definitions/addition.value" with:
19
+ """
20
+ In order to /^make 0 silly mistakes$/ do
21
+ puts "Testing: make 0 silly mistakes"
22
+ done
23
+ """
24
+ When I run `bundle exec cucumber features/addition.feature`
25
+ Then the stdout should contain:
26
+ """
27
+ Testing: make 0 silly mistakes
28
+ """
29
+
30
+ Scenario: testing successful value delivery of a feature
31
+ Given I have set up the environment with cucumber-value support
32
+ And I have set up the working calculator with metrics
33
+ And I have run some sample additions
34
+ And I have set up the addition feature
35
+ And I write to "features/step_definitions/addition.value" with:
36
+ """
37
+ In order to /^make 0 silly mistakes$/ do
38
+ puts "Testing: make 0 silly mistakes"
39
+ IO.read("metrics.txt") !~ /INCORRECT/
40
+ done
41
+ """
42
+ When I run `bundle exec cucumber features/addition.feature`
43
+ Then the stdout should contain:
44
+ """
45
+ : Delivered
46
+ """
47
+
48
+ Scenario: testing unsuccessful value delivery of a feature
49
+ Given I have set up the environment with cucumber-value support
50
+ And I have set up the broken calculator with metrics
51
+ And I have run some sample additions
52
+ And I have set up the addition feature
53
+ And I write to "features/step_definitions/addition.value" with:
54
+ """
55
+ In order to /^make 0 silly mistakes$/ do
56
+ puts "Testing: make 0 silly mistakes"
57
+ IO.read("metrics.txt") !~ /INCORRECT/
58
+ done
59
+ """
60
+ When I run `bundle exec cucumber features/addition.feature`
61
+ Then the stdout should contain:
62
+ """
63
+ : Not delivered
64
+ """
@@ -0,0 +1,3 @@
1
+ require 'cucumber/value/value_results'
2
+ require 'cucumber/value/value_tester'
3
+ require 'cucumber/value/hooks'
@@ -0,0 +1 @@
1
+ require 'cucumber/value/hooks/testable_value'
@@ -0,0 +1,31 @@
1
+ AfterConfiguration do
2
+ #grab the tests out into a global hash - brutal
3
+ puts "Parsing value tests..."
4
+ $value_tests = {}
5
+ pattern = %r/In order to (\/.*?\/) do([\d\D]*?)done/
6
+ Dir.glob('features/step_definitions/*.value').each do |file|
7
+ next unless File.file?(file)
8
+ puts "Scanning for value tests in " + File.basename(file)
9
+ value_test=(IO.read(file)).match(pattern)
10
+ # Hash of regexs and their associated tests
11
+ $value_tests[eval(value_test[1])] = Cucumber::Value::ValueTester.new value_test[2]
12
+ end
13
+ # Extended hash so it can output value delivery analysis - another nasty global
14
+ $value_results = Cucumber::Value::ValueResults.new
15
+ end
16
+
17
+ Before('@testable-value') do |s|
18
+ value = Regexp.new(/In order to (.*)$/).match(s.feature.description)[1].strip
19
+ puts "Testable value : " + value
20
+ $value_tests.each do |regex, value_tester|
21
+ if value.match(regex)
22
+ puts "Testable value being executed..."
23
+ value_tester.run_test
24
+ $value_results[s.feature.description] = value_tester.value?
25
+ end
26
+ end
27
+ end
28
+
29
+ at_exit do
30
+ $value_results.output
31
+ end
@@ -0,0 +1,13 @@
1
+ module Cucumber
2
+ module Value
3
+ # @author Colin Humphreys
4
+ class ValueResults < Hash
5
+ # Outputs whether value was delivered for each feature stored in the Hash
6
+ def output
7
+ self.each_pair do | feature, delivered |
8
+ puts feature + " : "+ ( delivered ? "Delivered" : "Not delivered" )
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module Cucumber
2
+ module Value
3
+ # @author Colin Humphreys
4
+ class ValueTester
5
+ # Initialises the ValueTester
6
+ # @param [String] test the code block to be executed for the value test
7
+ def initialize(test)
8
+ @test = test
9
+ end
10
+ # Runs the test block
11
+ def run_test
12
+ begin
13
+ @value = eval @test
14
+ rescue Exception => exc
15
+ # TODO: something sensible when tests aren't valid
16
+ @value = false
17
+ end
18
+ end
19
+ # Getter for whether the value has been delivered
20
+ # @return [Boolean] has the test passed?
21
+ def value?
22
+ @value
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ require "cucumber/value/value_results"
4
+
5
+ module Cucumber
6
+ module Value
7
+ describe ValueResults do
8
+ describe "output" do
9
+ it "should output whether the value was delivered" do
10
+ value_results = ValueResults.new
11
+ value_results["Sample feature definition"] = true
12
+ $stdout.should_receive(:puts).with(/Sample feature definition : Delivered/)
13
+ value_results.output
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ require "cucumber/value/value_tester"
4
+
5
+ module Cucumber
6
+ module Value
7
+ describe ValueTester do
8
+ before :each do
9
+ @valueTester = ValueTester.new "true"
10
+ end
11
+ describe "#new" do
12
+ it "should take a String parameter and return a ValueTester object" do
13
+ @valueTester.should be_an_instance_of ValueTester
14
+ end
15
+ end
16
+ describe "#run_test" do
17
+ it "should run the test code" do
18
+ @valueTester.run_test.should eql true
19
+ end
20
+ it "should not collapse and burn with an invalid test" do
21
+ badValueTester = ValueTester.new "gefafwsp"
22
+ badValueTester.run_test.should eql false
23
+ end
24
+ end
25
+ describe "#value?" do
26
+ it "should return whether the value was delivered" do
27
+ @valueTester.run_test
28
+ @valueTester.value?.should eql true
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,2 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-value
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Colin Humphreys
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &75482000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *75482000
25
+ - !ruby/object:Gem::Dependency
26
+ name: cucumber
27
+ requirement: &75481710 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *75481710
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &75481260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *75481260
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: &75480960 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *75480960
58
+ - !ruby/object:Gem::Dependency
59
+ name: guard
60
+ requirement: &75480750 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *75480750
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-cucumber
71
+ requirement: &75480510 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *75480510
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard-rspec
82
+ requirement: &75480210 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *75480210
91
+ - !ruby/object:Gem::Dependency
92
+ name: rake
93
+ requirement: &75479910 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *75479910
102
+ - !ruby/object:Gem::Dependency
103
+ name: aruba
104
+ requirement: &75479680 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *75479680
113
+ - !ruby/object:Gem::Dependency
114
+ name: cucumber
115
+ requirement: &75479440 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: *75479440
124
+ description: Assert the value of Cucumber features
125
+ email:
126
+ executables: []
127
+ extensions: []
128
+ extra_rdoc_files: []
129
+ files:
130
+ - .gitignore
131
+ - .travis.yml
132
+ - CHANGELOG.md
133
+ - Gemfile
134
+ - Guardfile
135
+ - LICENSE
136
+ - README.md
137
+ - Rakefile
138
+ - cucumber-value.gemspec
139
+ - features/step_definitions/cucumber_value_steps.rb
140
+ - features/support/env.rb
141
+ - features/test_value.feature
142
+ - lib/cucumber/value.rb
143
+ - lib/cucumber/value/hooks.rb
144
+ - lib/cucumber/value/hooks/testable_value.rb
145
+ - lib/cucumber/value/value_results.rb
146
+ - lib/cucumber/value/value_tester.rb
147
+ - spec/cucumber/value/value_results_spec.rb
148
+ - spec/cucumber/value/value_tester_spec.rb
149
+ - spec/spec_helper.rb
150
+ homepage: https://github.com/hatofmonkeys/cucumber-value
151
+ licenses:
152
+ - MIT
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ segments:
164
+ - 0
165
+ hash: -518837293
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ segments:
173
+ - 0
174
+ hash: -518837293
175
+ requirements: []
176
+ rubyforge_project:
177
+ rubygems_version: 1.8.10
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: cucumber-value-0.0.1
181
+ test_files: []
182
+ has_rdoc: