mdoel-cukesteps 0.2.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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mike Doel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,21 @@
1
+ = cukesteps
2
+
3
+ cukesteps is a gem containing general purpose step definitions for the Cucumber BDD framework.
4
+
5
+ Cucumber provides a single webrat_steps.rb file containing generic steps. This gem provides more.
6
+
7
+ To use it, add:
8
+
9
+ require 'mdoel-cukesteps'
10
+
11
+ to your features/support/env.rb file
12
+
13
+ = To Do
14
+
15
+ - make the gem usable with different testing frameworks and/or make it framework agnostic (currently uses Rspec)
16
+ - test these tests (see http://github.com/mdoel/cukesteps-test/tree/master)
17
+
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2009 Mike Doel. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gemspec|
7
+ gemspec.name = "cukesteps"
8
+ gemspec.summary = "General purpose step definitions for Cucumber"
9
+ gemspec.email = "mike@mikedoel.com"
10
+ gemspec.homepage = "http://github.com/mdoel/cukesteps/tree/master"
11
+ gemspec.description = "General purpose step definitions for the ruby BDD framework Cucumber"
12
+ gemspec.authors = ["Mike Doel"]
13
+ end
14
+ rescue LoadError
15
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
16
+ end
17
+
18
+ require 'rake/testtask'
19
+ Rake::TestTask.new(:test) do |test|
20
+ test.libs << 'lib' << 'test'
21
+ test.pattern = 'test/**/*_test.rb'
22
+ test.verbose = true
23
+ end
24
+
25
+ begin
26
+ require 'rcov/rcovtask'
27
+ Rcov::RcovTask.new do |test|
28
+ test.libs << 'test'
29
+ test.pattern = 'test/**/*_test.rb'
30
+ test.verbose = true
31
+ end
32
+ rescue LoadError
33
+ task :rcov do
34
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
35
+ end
36
+ end
37
+
38
+
39
+ task :default => :test
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ if File.exist?('VERSION.yml')
44
+ config = YAML.load(File.read('VERSION.yml'))
45
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
46
+ else
47
+ version = ""
48
+ end
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "cukesteps #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/cukesteps.gemspec ADDED
@@ -0,0 +1,49 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{cukesteps}
5
+ s.version = "0.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Mike Doel"]
9
+ s.date = %q{2009-06-01}
10
+ s.description = %q{General purpose step definitions for the ruby BDD framework Cucumber}
11
+ s.email = %q{mike@mikedoel.com}
12
+ s.extra_rdoc_files = [
13
+ "LICENSE",
14
+ "README.rdoc"
15
+ ]
16
+ s.files = [
17
+ ".document",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "cukesteps.gemspec",
23
+ "lib/common_steps.rb",
24
+ "lib/cuke_association_helpers.rb",
25
+ "lib/cukesteps.rb",
26
+ "pkg/cukesteps-0.1.0.gem",
27
+ "test/cukesteps_test.rb",
28
+ "test/test_helper.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/mdoel/cukesteps/tree/master}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.3}
34
+ s.summary = %q{General purpose step definitions for Cucumber}
35
+ s.test_files = [
36
+ "test/cukesteps_test.rb",
37
+ "test/test_helper.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ else
46
+ end
47
+ else
48
+ end
49
+ end
@@ -0,0 +1,53 @@
1
+ Then /^I debug$/ do
2
+ debugger
3
+ end
4
+
5
+ Then /^save_and_open_page$/ do
6
+ save_and_open_page
7
+ end
8
+
9
+ Then /^I wait for ([0-9]+) seconds$/ do |delay|
10
+ sleep delay.to_i
11
+ end
12
+
13
+ # Steps that are generally useful and help encourage use of semantic
14
+ # IDs and Class Names in your markup. In the steps below, a match following
15
+ # "the" will verify the presences of an element with a given ID while a match following
16
+ # "a" or "an" will verify the presence an element of a given class.
17
+ Then /^I should see a (\S+) in the (\S+)$/ do |element, containing_element|
18
+ response.should have_tag("##{containing_element} .#{element}")
19
+ end
20
+
21
+ Then /^I should see the (\S+) in the (\S+)$/ do |element, containing_element|
22
+ response.should have_tag("##{containing_element} ##{element}")
23
+ end
24
+
25
+ Then /^I should see (\d+) (\S+) in the (\S+)$/ do |count, element, containing_element|
26
+ response.should have_tag("##{containing_element} .#{element.singularize}",:count => count.to_i)
27
+ end
28
+
29
+ Then /^I should see (\d+) to (\d+) (\S+) in the (\S+)$/ do |min, max, element, containing_element|
30
+ response.should have_tag("##{containing_element} .#{element.singularize}",min.to_i..max.to_i)
31
+ end
32
+
33
+ Then /^the (\S+) in the (\S+) should contain (a|an|the) (\S+)$/ do |middle_element, outer_element, a, inner_element|
34
+ response.should have_tag("##{outer_element} .#{middle_element} .#{inner_element}")
35
+ end
36
+
37
+ Then /^I should see the (\S+)$/ do |element_id|
38
+ response.should have_tag("##{element_id}")
39
+ end
40
+
41
+ Then /^I should see (a|an) (\S+)$/ do |a, element_class|
42
+ response.should have_tag(".#{element_class}")
43
+ end
44
+
45
+ Then /^(\d+) (\S+) should exist$/ do |count, element_class|
46
+ klass = element_class.singularize.capitalize.constantize
47
+ klass.count.should eql(count.to_i)
48
+ end
49
+
50
+ # Steps for creating objects that can be associated with other objects
51
+ Given /^the following (\S+) exist$/ do |model_class_name,table|
52
+ build_cuke_objects model_class_name, table
53
+ end
@@ -0,0 +1,74 @@
1
+ module CukeAssociationHelpers
2
+
3
+ def cuke_association_builders(associations = {})
4
+ @@associated_cuke_builders ||= {}
5
+ associations.each { |k,v| @@associated_cuke_builders[k] = v }
6
+ end
7
+
8
+ def build_cuke_objects(model_class_name, table)
9
+ @created_objects ||= {}
10
+ @model_class_name = model_class_name.downcase.singularize
11
+ build_cuke_objects_with_associations(table)
12
+ end
13
+
14
+ def build_cuke_objects_with_associations(table)
15
+ table.hashes.each do |params_hash|
16
+ build_one_cuke_object params_hash
17
+ end
18
+ end
19
+
20
+ def build_one_cuke_object(params_hash)
21
+ hash = duplicate_with_lc_keys(params_hash)
22
+ object_name = hash.delete(@model_class_name)
23
+ @created_objects[@model_class_name] ||= {} if !object_name.nil?
24
+ attributes = assemble_attributes(hash,object_name)
25
+ new_object = create_model(@model_class_name,attributes)
26
+ @created_objects[@model_class_name][object_name] = new_object if !object_name.nil?
27
+ end
28
+
29
+ def duplicate_with_lc_keys(hash)
30
+ normalized = {}
31
+ hash.each {|k,v| normalized[k.downcase] = v}
32
+ normalized
33
+ end
34
+
35
+ def assemble_attributes(hash,object_name)
36
+ attributes = {}
37
+ hash.each do |key,value|
38
+ symbolized_key = key.downcase.gsub(' ','_').to_sym
39
+ if @created_objects[key].nil?
40
+ attributes[symbolized_key] = build_value(symbolized_key,value)
41
+ else
42
+ attributes[symbolized_key] = @created_objects[key][value]
43
+ end
44
+ end
45
+ attributes
46
+ end
47
+
48
+ def build_value(key,value)
49
+ if @@associated_cuke_builders[key].nil?
50
+ value
51
+ else
52
+ build_value_from_association(key,value)
53
+ end
54
+ end
55
+
56
+ def build_value_from_association(key,value)
57
+ klass = class_from_symbol(key)
58
+ builder = @@associated_cuke_builders[key]
59
+ if builder == :build_associated_via_find_by_name
60
+ klass.find_by_name(value)
61
+ else
62
+ klass.send(builder,value)
63
+ end
64
+ end
65
+
66
+ def class_from_symbol(key)
67
+ key.to_s.capitalize.constantize
68
+ end
69
+
70
+ def create_model(model_name, attributes={})
71
+ send("create_#{model_name.gsub(' ','_')}",attributes)
72
+ end
73
+ end
74
+ World(CukeAssociationHelpers)
data/lib/cukesteps.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'common_steps'
2
+ #require 'lib/cuke_association_helpers.rb'
Binary file
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class CukestepsTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'cukesteps'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdoel-cukesteps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Doel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-01 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: General purpose step definitions for the ruby BDD framework Cucumber
17
+ email: mike@mikedoel.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - LICENSE
28
+ - README.rdoc
29
+ - Rakefile
30
+ - VERSION
31
+ - cukesteps.gemspec
32
+ - lib/common_steps.rb
33
+ - lib/cuke_association_helpers.rb
34
+ - lib/cukesteps.rb
35
+ - pkg/cukesteps-0.1.0.gem
36
+ - test/cukesteps_test.rb
37
+ - test/test_helper.rb
38
+ has_rdoc: false
39
+ homepage: http://github.com/mdoel/cukesteps/tree/master
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: General purpose step definitions for Cucumber
64
+ test_files:
65
+ - test/cukesteps_test.rb
66
+ - test/test_helper.rb