makandra-cucumber_factory 1.1.3 → 1.1.5
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/.gitignore +3 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +2 -2
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/cucumber_factory.gemspec +80 -0
- data/lib/cucumber_factory.rb +2 -0
- data/lib/cucumber_factory/factory.rb +83 -0
- data/spec/app_root/config/database.yml +21 -0
- data/spec/app_root/log/.gitignore +1 -0
- data/spec/app_root/script/console +7 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- metadata +31 -4
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Henning Koch
|
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
CHANGED
@@ -9,9 +9,9 @@ Install the gem:
|
|
9
9
|
sudo gem install makandra-cucumber_factory
|
10
10
|
|
11
11
|
Add the following to your <tt>Initializer.run</tt> block in your <tt>environment.rb</tt>:
|
12
|
-
config.gem '
|
12
|
+
config.gem 'makandra-cucumber_factory', :lib => 'cucumber_factory', :source => 'http://gems.github.com'
|
13
13
|
|
14
|
-
Create a step definition stub in <tt>features/step_definitions/factory_steps.rb
|
14
|
+
Create a step definition stub in <tt>features/step_definitions/factory_steps.rb</tt>, which just says
|
15
15
|
Cucumber::Factory.add_steps(this)
|
16
16
|
|
17
17
|
== Example
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rake'
|
2
|
+
# require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
desc 'Default: Run all specs.'
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
desc "Run all specs"
|
10
|
+
Spec::Rake::SpecTask.new() do |t|
|
11
|
+
t.spec_opts = ['--options', "\"spec/spec.opts\""]
|
12
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the aegis plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'Aegis'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'jeweler'
|
26
|
+
Jeweler::Tasks.new do |gemspec|
|
27
|
+
gemspec.name = "cucumber_factory"
|
28
|
+
gemspec.summary = "Create records from Cucumber features without writing step definitions."
|
29
|
+
gemspec.email = "github@makandra.de"
|
30
|
+
gemspec.homepage = "http://github.com/makandra/cucumber_factory"
|
31
|
+
gemspec.description = "Create records from Cucumber features without writing step definitions."
|
32
|
+
gemspec.authors = ["Henning Koch"]
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
36
|
+
end
|
37
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.5
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{cucumber_factory}
|
5
|
+
s.version = "1.1.5"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Henning Koch"]
|
9
|
+
s.date = %q{2009-09-07}
|
10
|
+
s.description = %q{Create records from Cucumber features without writing step definitions.}
|
11
|
+
s.email = %q{github@makandra.de}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"MIT-LICENSE",
|
18
|
+
"README.rdoc",
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION",
|
21
|
+
"cucumber_factory.gemspec",
|
22
|
+
"lib/cucumber_factory.rb",
|
23
|
+
"lib/cucumber_factory/factory.rb",
|
24
|
+
"spec/app_root/app/controllers/application_controller.rb",
|
25
|
+
"spec/app_root/app/models/movie.rb",
|
26
|
+
"spec/app_root/app/models/user.rb",
|
27
|
+
"spec/app_root/config/boot.rb",
|
28
|
+
"spec/app_root/config/database.yml",
|
29
|
+
"spec/app_root/config/environment.rb",
|
30
|
+
"spec/app_root/config/environments/in_memory.rb",
|
31
|
+
"spec/app_root/config/environments/mysql.rb",
|
32
|
+
"spec/app_root/config/environments/postgresql.rb",
|
33
|
+
"spec/app_root/config/environments/sqlite.rb",
|
34
|
+
"spec/app_root/config/environments/sqlite3.rb",
|
35
|
+
"spec/app_root/config/routes.rb",
|
36
|
+
"spec/app_root/db/migrate/001_create_movies.rb",
|
37
|
+
"spec/app_root/db/migrate/002_create_users.rb",
|
38
|
+
"spec/app_root/lib/console_with_fixtures.rb",
|
39
|
+
"spec/app_root/log/.gitignore",
|
40
|
+
"spec/app_root/script/console",
|
41
|
+
"spec/factory_spec.rb",
|
42
|
+
"spec/rcov.opts",
|
43
|
+
"spec/spec.opts",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.has_rdoc = true
|
47
|
+
s.homepage = %q{http://github.com/makandra/cucumber_factory}
|
48
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
s.rubygems_version = %q{1.3.1}
|
51
|
+
s.summary = %q{Create records from Cucumber features without writing step definitions.}
|
52
|
+
s.test_files = [
|
53
|
+
"spec/app_root/app/models/movie.rb",
|
54
|
+
"spec/app_root/app/models/user.rb",
|
55
|
+
"spec/app_root/app/controllers/application_controller.rb",
|
56
|
+
"spec/app_root/config/environment.rb",
|
57
|
+
"spec/app_root/config/environments/mysql.rb",
|
58
|
+
"spec/app_root/config/environments/postgresql.rb",
|
59
|
+
"spec/app_root/config/environments/sqlite3.rb",
|
60
|
+
"spec/app_root/config/environments/in_memory.rb",
|
61
|
+
"spec/app_root/config/environments/sqlite.rb",
|
62
|
+
"spec/app_root/config/boot.rb",
|
63
|
+
"spec/app_root/config/routes.rb",
|
64
|
+
"spec/app_root/db/migrate/002_create_users.rb",
|
65
|
+
"spec/app_root/db/migrate/001_create_movies.rb",
|
66
|
+
"spec/app_root/lib/console_with_fixtures.rb",
|
67
|
+
"spec/factory_spec.rb",
|
68
|
+
"spec/spec_helper.rb"
|
69
|
+
]
|
70
|
+
|
71
|
+
if s.respond_to? :specification_version then
|
72
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
73
|
+
s.specification_version = 2
|
74
|
+
|
75
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
76
|
+
else
|
77
|
+
end
|
78
|
+
else
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Cucumber
|
2
|
+
module Factory
|
3
|
+
|
4
|
+
def self.add_steps(world)
|
5
|
+
steps.each do |step|
|
6
|
+
world.instance_eval do
|
7
|
+
Given(step[0], &step[1].bind(world))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.steps
|
13
|
+
[
|
14
|
+
[
|
15
|
+
/^"([^\"]*)" is a (.+?)( with the .+?)?$/,
|
16
|
+
lambda { |name, raw_model, raw_attributes| Cucumber::Factory.parse_named_creation(self, name, raw_model, raw_attributes) }
|
17
|
+
],
|
18
|
+
[
|
19
|
+
/^there is a (.+?)( with the .+?)?$/,
|
20
|
+
lambda { |raw_model, raw_attributes| Cucumber::Factory.parse_creation(self, raw_model, raw_attributes) }
|
21
|
+
]
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse(world, command)
|
26
|
+
command = command.sub(/^When |Given |Then /, "")
|
27
|
+
steps.each do |step|
|
28
|
+
match = step[0].match(command)
|
29
|
+
if match
|
30
|
+
step[1].bind(world).call(*match.captures)
|
31
|
+
return
|
32
|
+
end
|
33
|
+
end
|
34
|
+
raise "No step definition for: #{command}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.parse_named_creation(world, name, raw_model, raw_attributes)
|
38
|
+
record = parse_creation(world, raw_model, raw_attributes)
|
39
|
+
variable = variable_name(name)
|
40
|
+
world.instance_variable_set variable, record
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.parse_creation(world, raw_model, raw_attributes)
|
44
|
+
model_class = raw_model.camelize.constantize
|
45
|
+
attributes = {}
|
46
|
+
if raw_attributes.present? && raw_attributes.strip.present?
|
47
|
+
raw_attributes.scan(/(the|and|with| )+(.*?) ("([^\"]*)"|above)/).each do |fragment|
|
48
|
+
value = nil
|
49
|
+
attribute = fragment[1].to_sym
|
50
|
+
value_type = fragment[2] # 'above' or a quoted string
|
51
|
+
value = fragment[3]
|
52
|
+
association = model_class.reflect_on_association(attribute)
|
53
|
+
if association.present?
|
54
|
+
if value_type == "above"
|
55
|
+
value = association.klass.last or raise "There is no last #{attribute}"
|
56
|
+
else
|
57
|
+
value = world.instance_variable_get(variable_name(value))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
attributes[attribute] = value
|
61
|
+
end
|
62
|
+
end
|
63
|
+
create_record(model_class, attributes)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.variable_name(prose)
|
67
|
+
name = prose.downcase.gsub(/[^a-z0-9_]+/, '_')
|
68
|
+
name = name.gsub(/^_+/, '').gsub(/_+$/, '')
|
69
|
+
name = "_#{name}" unless name.length >= 0 && name =~ /^[a-z]/
|
70
|
+
:"@#{name}"
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def self.create_record(model_class, attributes)
|
76
|
+
create_method = [:make, :create!, :new].detect do |method_name|
|
77
|
+
model_class.respond_to? method_name
|
78
|
+
end
|
79
|
+
model_class.send(create_method, attributes)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
in_memory:
|
2
|
+
adapter: sqlite3
|
3
|
+
database: ":memory:"
|
4
|
+
verbosity: quiet
|
5
|
+
sqlite:
|
6
|
+
adapter: sqlite
|
7
|
+
dbfile: plugin_test.sqlite.db
|
8
|
+
sqlite3:
|
9
|
+
adapter: sqlite3
|
10
|
+
dbfile: plugin_test.sqlite3.db
|
11
|
+
postgresql:
|
12
|
+
adapter: postgresql
|
13
|
+
username: postgres
|
14
|
+
password: postgres
|
15
|
+
database: plugin_test
|
16
|
+
mysql:
|
17
|
+
adapter: mysql
|
18
|
+
host: localhost
|
19
|
+
username: root
|
20
|
+
password:
|
21
|
+
database: plugin_test
|
@@ -0,0 +1 @@
|
|
1
|
+
*.log
|
data/spec/rcov.opts
ADDED
data/spec/spec.opts
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: makandra-cucumber_factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
@@ -13,7 +13,7 @@ date: 2009-09-07 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: Create records from Cucumber features without writing step definitions.
|
17
17
|
email: github@makandra.de
|
18
18
|
executables: []
|
19
19
|
|
@@ -22,10 +22,37 @@ extensions: []
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README.rdoc
|
24
24
|
files:
|
25
|
+
- .gitignore
|
26
|
+
- MIT-LICENSE
|
25
27
|
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- cucumber_factory.gemspec
|
31
|
+
- lib/cucumber_factory.rb
|
32
|
+
- lib/cucumber_factory/factory.rb
|
33
|
+
- spec/app_root/app/controllers/application_controller.rb
|
34
|
+
- spec/app_root/app/models/movie.rb
|
35
|
+
- spec/app_root/app/models/user.rb
|
36
|
+
- spec/app_root/config/boot.rb
|
37
|
+
- spec/app_root/config/database.yml
|
38
|
+
- spec/app_root/config/environment.rb
|
39
|
+
- spec/app_root/config/environments/in_memory.rb
|
40
|
+
- spec/app_root/config/environments/mysql.rb
|
41
|
+
- spec/app_root/config/environments/postgresql.rb
|
42
|
+
- spec/app_root/config/environments/sqlite.rb
|
43
|
+
- spec/app_root/config/environments/sqlite3.rb
|
44
|
+
- spec/app_root/config/routes.rb
|
45
|
+
- spec/app_root/db/migrate/001_create_movies.rb
|
46
|
+
- spec/app_root/db/migrate/002_create_users.rb
|
47
|
+
- spec/app_root/lib/console_with_fixtures.rb
|
48
|
+
- spec/app_root/log/.gitignore
|
49
|
+
- spec/app_root/script/console
|
50
|
+
- spec/factory_spec.rb
|
51
|
+
- spec/rcov.opts
|
52
|
+
- spec/spec.opts
|
53
|
+
- spec/spec_helper.rb
|
26
54
|
has_rdoc: true
|
27
55
|
homepage: http://github.com/makandra/cucumber_factory
|
28
|
-
licenses:
|
29
56
|
post_install_message:
|
30
57
|
rdoc_options:
|
31
58
|
- --charset=UTF-8
|
@@ -46,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
73
|
requirements: []
|
47
74
|
|
48
75
|
rubyforge_project:
|
49
|
-
rubygems_version: 1.
|
76
|
+
rubygems_version: 1.2.0
|
50
77
|
signing_key:
|
51
78
|
specification_version: 2
|
52
79
|
summary: Create records from Cucumber features without writing step definitions.
|