cucumber_factory 1.1.7
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 +40 -0
- 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/app/controllers/application_controller.rb +2 -0
- data/spec/app_root/app/models/movie.rb +6 -0
- data/spec/app_root/app/models/user.rb +3 -0
- data/spec/app_root/config/boot.rb +114 -0
- data/spec/app_root/config/database.yml +21 -0
- data/spec/app_root/config/environment.rb +14 -0
- data/spec/app_root/config/environments/in_memory.rb +0 -0
- data/spec/app_root/config/environments/mysql.rb +0 -0
- data/spec/app_root/config/environments/postgresql.rb +0 -0
- data/spec/app_root/config/environments/sqlite.rb +0 -0
- data/spec/app_root/config/environments/sqlite3.rb +0 -0
- data/spec/app_root/config/routes.rb +4 -0
- data/spec/app_root/db/migrate/001_create_movies.rb +17 -0
- data/spec/app_root/db/migrate/002_create_users.rb +14 -0
- data/spec/app_root/lib/console_with_fixtures.rb +4 -0
- data/spec/app_root/log/.gitignore +1 -0
- data/spec/app_root/script/console +7 -0
- data/spec/factory_spec.rb +72 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +77 -0
- metadata +98 -0
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
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
= Cucumber Factory - create ActiveRecord objects without step definitions
|
2
|
+
|
3
|
+
Cucumber Factory allows you to create ActiveRecord objects directly from your {Cucumber}[http://cukes.info/] features. No step definitions required.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Install the gem:
|
8
|
+
sudo gem sources -a http://gems.github.com
|
9
|
+
sudo gem install makandra-cucumber_factory
|
10
|
+
|
11
|
+
Add the following to your <tt>Initializer.run</tt> block in your <tt>environment.rb</tt>:
|
12
|
+
config.gem 'makandra-cucumber_factory', :lib => 'cucumber_factory', :source => 'http://gems.github.com'
|
13
|
+
|
14
|
+
Create a step definition stub in <tt>features/step_definitions/factory_steps.rb</tt>, which just says
|
15
|
+
Cucumber::Factory.add_steps(self)
|
16
|
+
|
17
|
+
== Example
|
18
|
+
|
19
|
+
The following will call {Movie.make}[http://github.com/notahat/machinist/tree/master], Movie.create! or Movie.new, depending on what's available:
|
20
|
+
Given there is a movie
|
21
|
+
|
22
|
+
To create a new record with attributes set, you can say:
|
23
|
+
Given there is a movie with the title "Sunshine" and the year "2007"
|
24
|
+
|
25
|
+
The following will also store the created record in <tt>@sunshine</tt>:
|
26
|
+
Given "Sunshine" is a movie with the title "Sunshine" and the year "2007"
|
27
|
+
|
28
|
+
To set associations you can refer to other records by name:
|
29
|
+
Given "Before Sunrise" is a movie
|
30
|
+
And "Before Sunset" is a movie with the prequel "Before Sunrise"
|
31
|
+
|
32
|
+
You can also refer to the last created object of a kind by saying "above":
|
33
|
+
Given there is a movie with the title "Before Sunrise"
|
34
|
+
And "Before Sunset" is a movie with the prequel above
|
35
|
+
|
36
|
+
=== Credits
|
37
|
+
|
38
|
+
Henning Koch
|
39
|
+
|
40
|
+
{www.makandra.de}[http://www.makandra.de/]
|
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 = "Cucumber Factory allows you to create ActiveRecord models from your Cucumber features without writing step definitions for each model."
|
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.7
|
@@ -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.7"
|
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-18}
|
10
|
+
s.description = %q{Cucumber Factory allows you to create ActiveRecord models from your Cucumber features without writing step definitions for each model.}
|
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].gsub(" ", "_").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,114 @@
|
|
1
|
+
# Allow customization of the rails framework path
|
2
|
+
RAILS_FRAMEWORK_ROOT = (ENV['RAILS_FRAMEWORK_ROOT'] || "#{File.dirname(__FILE__)}/../../../../../../vendor/rails") unless defined?(RAILS_FRAMEWORK_ROOT)
|
3
|
+
|
4
|
+
# Don't change this file!
|
5
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
6
|
+
|
7
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
8
|
+
|
9
|
+
module Rails
|
10
|
+
class << self
|
11
|
+
def boot!
|
12
|
+
unless booted?
|
13
|
+
preinitialize
|
14
|
+
pick_boot.run
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def booted?
|
19
|
+
defined? Rails::Initializer
|
20
|
+
end
|
21
|
+
|
22
|
+
def pick_boot
|
23
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
24
|
+
end
|
25
|
+
|
26
|
+
def vendor_rails?
|
27
|
+
File.exist?(RAILS_FRAMEWORK_ROOT)
|
28
|
+
end
|
29
|
+
|
30
|
+
def preinitialize
|
31
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def preinitializer_path
|
35
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Boot
|
40
|
+
def run
|
41
|
+
load_initializer
|
42
|
+
Rails::Initializer.run(:set_load_path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class VendorBoot < Boot
|
47
|
+
def load_initializer
|
48
|
+
require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
|
49
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class GemBoot < Boot
|
54
|
+
def load_initializer
|
55
|
+
self.class.load_rubygems
|
56
|
+
load_rails_gem
|
57
|
+
require 'initializer'
|
58
|
+
end
|
59
|
+
|
60
|
+
def load_rails_gem
|
61
|
+
if version = self.class.gem_version
|
62
|
+
gem 'rails', version
|
63
|
+
else
|
64
|
+
gem 'rails'
|
65
|
+
end
|
66
|
+
rescue Gem::LoadError => load_error
|
67
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
68
|
+
exit 1
|
69
|
+
end
|
70
|
+
|
71
|
+
class << self
|
72
|
+
def rubygems_version
|
73
|
+
Gem::RubyGemsVersion rescue nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def gem_version
|
77
|
+
if defined? RAILS_GEM_VERSION
|
78
|
+
RAILS_GEM_VERSION
|
79
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
80
|
+
ENV['RAILS_GEM_VERSION']
|
81
|
+
else
|
82
|
+
parse_gem_version(read_environment_rb)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def load_rubygems
|
87
|
+
require 'rubygems'
|
88
|
+
min_version = '1.1.1'
|
89
|
+
unless rubygems_version >= min_version
|
90
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
91
|
+
exit 1
|
92
|
+
end
|
93
|
+
|
94
|
+
rescue LoadError
|
95
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
96
|
+
exit 1
|
97
|
+
end
|
98
|
+
|
99
|
+
def parse_gem_version(text)
|
100
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
def read_environment_rb
|
105
|
+
environment_rb = "#{RAILS_ROOT}/config/environment.rb"
|
106
|
+
environment_rb = "#{HELPER_RAILS_ROOT}/config/environment.rb" unless File.exists?(environment_rb)
|
107
|
+
File.read(environment_rb)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# All that for this:
|
114
|
+
Rails.boot!
|
@@ -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,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
2
|
+
|
3
|
+
Rails::Initializer.run do |config|
|
4
|
+
config.cache_classes = false
|
5
|
+
config.whiny_nils = true
|
6
|
+
config.action_controller.session = { :key => "_myapp_session", :secret => "gwirofjweroijger8924rt2zfwehfuiwehb1378rifowenfoqwphf23" }
|
7
|
+
config.plugin_locators.unshift(
|
8
|
+
Class.new(Rails::Plugin::Locator) do
|
9
|
+
def plugins
|
10
|
+
[Rails::Plugin.new(File.expand_path('.'))]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
) unless defined?(PluginTestHelper::PluginLocator)
|
14
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateMovies < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :movies do |t|
|
5
|
+
t.string :title
|
6
|
+
t.integer :year
|
7
|
+
t.integer :prequel_id
|
8
|
+
t.integer :reviewer_id
|
9
|
+
t.integer :box_office_result
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :movies
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
# Loads fixtures into the database when running the test app via the console
|
2
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Rails.root, '../fixtures/*.{yml,csv}'))).each do |fixture_file|
|
3
|
+
Fixtures.create_fixtures(File.join(Rails.root, '../fixtures'), File.basename(fixture_file, '.*'))
|
4
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
*.log
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Cucumber::Factory do
|
4
|
+
|
5
|
+
describe 'add_steps' do
|
6
|
+
|
7
|
+
it "should add Given rules to the world" do
|
8
|
+
world = mock('world').as_null_object
|
9
|
+
world.should_receive(:Given).exactly(2).times
|
10
|
+
Cucumber::Factory.add_steps(world)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'variable_name' do
|
16
|
+
|
17
|
+
it "should translate natural language to instance variable names" do
|
18
|
+
Cucumber::Factory.variable_name("movie").should == :'@movie'
|
19
|
+
Cucumber::Factory.variable_name("Some Movie").should == :'@some_movie'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should make sure the generated instance variable names are legal" do
|
23
|
+
Cucumber::Factory.variable_name("1973").should == :'@_1973'
|
24
|
+
Cucumber::Factory.variable_name("%$§").should == :'@_'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'parse' do
|
30
|
+
|
31
|
+
before(:each) do
|
32
|
+
@world = Object.new
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should create records" do
|
36
|
+
Movie.should_receive(:create!).with({})
|
37
|
+
Cucumber::Factory.parse(@world, "Given there is a movie")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should create records with attributes" do
|
41
|
+
Movie.should_receive(:create!).with({ :title => "Sunshine", :year => "2007" })
|
42
|
+
Cucumber::Factory.parse(@world, 'Given there is a movie with the title "Sunshine" and the year "2007"')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should create records with attributes containing spaces" do
|
46
|
+
Movie.should_receive(:create!).with({ :box_office_result => "99999999" })
|
47
|
+
Cucumber::Factory.parse(@world, 'Given there is a movie with the box office result "99999999"')
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should set instance variables in the world" do
|
51
|
+
Cucumber::Factory.parse(@world, 'Given "Sunshine" is a movie with the title "Sunshine" and the year "2007"')
|
52
|
+
@world.instance_variable_get(:'@sunshine').title.should == "Sunshine"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should understand pointers to instance variables" do
|
56
|
+
Cucumber::Factory.parse(@world, 'Given "Before Sunrise" is a movie with the title "Before Sunrise"')
|
57
|
+
Cucumber::Factory.parse(@world, 'Given "Before Sunset" is a movie with the title "Before Sunset" and the prequel "Before Sunrise"')
|
58
|
+
@world.instance_variable_get(:'@before_sunset').prequel.title.should == "Before Sunrise"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should allow to point to a previously created record through 'above'" do
|
62
|
+
Cucumber::Factory.parse(@world, 'Given there is a user with the name "Jane"')
|
63
|
+
Cucumber::Factory.parse(@world, 'Given there is a movie with the title "Before Sunrise"')
|
64
|
+
Cucumber::Factory.parse(@world, 'Given there is a movie with the title "Before Sunset" and the reviewer above and the prequel above')
|
65
|
+
@before_sunset = Movie.find_by_title!("Before Sunset")
|
66
|
+
@before_sunset.prequel.title.should == "Before Sunrise"
|
67
|
+
@before_sunset.reviewer.name.should == "Jane"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/spec/rcov.opts
ADDED
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__), "/../lib" )
|
2
|
+
#require 'lib/cucumber_factory'
|
3
|
+
# Dir["spec/fixtures/**/*.rb"].each {|f| require f}
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
# Set the default environment to sqlite3's in_memory database
|
8
|
+
ENV['RAILS_ENV'] ||= 'in_memory'
|
9
|
+
|
10
|
+
# Load the Rails environment and testing framework
|
11
|
+
require "#{File.dirname(__FILE__)}/app_root/config/environment"
|
12
|
+
require "#{File.dirname(__FILE__)}/../lib/cucumber_factory"
|
13
|
+
require 'spec/rails'
|
14
|
+
|
15
|
+
# Undo changes to RAILS_ENV
|
16
|
+
silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
|
17
|
+
|
18
|
+
# Run the migrations
|
19
|
+
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
|
20
|
+
|
21
|
+
Spec::Runner.configure do |config|
|
22
|
+
config.use_transactional_fixtures = true
|
23
|
+
config.use_instantiated_fixtures = false
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
## This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
28
|
+
## from the project root directory.
|
29
|
+
#ENV["RAILS_ENV"] ||= 'test'
|
30
|
+
#require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
|
31
|
+
#require 'spec/autorun'
|
32
|
+
#require 'spec/rails'
|
33
|
+
#
|
34
|
+
## Requires supporting files with custom matchers and macros, etc,
|
35
|
+
## in ./support/ and its subdirectories.
|
36
|
+
#Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
37
|
+
#
|
38
|
+
#Spec::Runner.configure do |config|
|
39
|
+
# # If you're not using ActiveRecord you should remove these
|
40
|
+
# # lines, delete config/database.yml and disable :active_record
|
41
|
+
# # in your config/boot.rb
|
42
|
+
# config.use_transactional_fixtures = true
|
43
|
+
# config.use_instantiated_fixtures = false
|
44
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
45
|
+
#
|
46
|
+
# # == Fixtures
|
47
|
+
# #
|
48
|
+
# # You can declare fixtures for each example_group like this:
|
49
|
+
# # describe "...." do
|
50
|
+
# # fixtures :table_a, :table_b
|
51
|
+
# #
|
52
|
+
# # Alternatively, if you prefer to declare them only once, you can
|
53
|
+
# # do so right here. Just uncomment the next line and replace the fixture
|
54
|
+
# # names with your fixtures.
|
55
|
+
# #
|
56
|
+
# # config.global_fixtures = :table_a, :table_b
|
57
|
+
# #
|
58
|
+
# # If you declare global fixtures, be aware that they will be declared
|
59
|
+
# # for all of your examples, even those that don't use them.
|
60
|
+
# #
|
61
|
+
# # You can also declare which fixtures to use (for example fixtures for test/fixtures):
|
62
|
+
# #
|
63
|
+
# # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
64
|
+
# #
|
65
|
+
# # == Mock Framework
|
66
|
+
# #
|
67
|
+
# # RSpec uses it's own mocking framework by default. If you prefer to
|
68
|
+
# # use mocha, flexmock or RR, uncomment the appropriate line:
|
69
|
+
# #
|
70
|
+
# # config.mock_with :mocha
|
71
|
+
# # config.mock_with :flexmock
|
72
|
+
# # config.mock_with :rr
|
73
|
+
# #
|
74
|
+
# # == Notes
|
75
|
+
# #
|
76
|
+
# # For more information take a look at Spec::Runner::Configuration and Spec::Runner
|
77
|
+
#end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cucumber_factory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Henning Koch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-18 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Cucumber Factory allows you to create ActiveRecord models from your Cucumber features without writing step definitions for each model.
|
17
|
+
email: github@makandra.de
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- MIT-LICENSE
|
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
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/makandra/cucumber_factory
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --charset=UTF-8
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 2
|
81
|
+
summary: Create records from Cucumber features without writing step definitions.
|
82
|
+
test_files:
|
83
|
+
- spec/app_root/app/models/movie.rb
|
84
|
+
- spec/app_root/app/models/user.rb
|
85
|
+
- spec/app_root/app/controllers/application_controller.rb
|
86
|
+
- spec/app_root/config/environment.rb
|
87
|
+
- spec/app_root/config/environments/mysql.rb
|
88
|
+
- spec/app_root/config/environments/postgresql.rb
|
89
|
+
- spec/app_root/config/environments/sqlite3.rb
|
90
|
+
- spec/app_root/config/environments/in_memory.rb
|
91
|
+
- spec/app_root/config/environments/sqlite.rb
|
92
|
+
- spec/app_root/config/boot.rb
|
93
|
+
- spec/app_root/config/routes.rb
|
94
|
+
- spec/app_root/db/migrate/002_create_users.rb
|
95
|
+
- spec/app_root/db/migrate/001_create_movies.rb
|
96
|
+
- spec/app_root/lib/console_with_fixtures.rb
|
97
|
+
- spec/factory_spec.rb
|
98
|
+
- spec/spec_helper.rb
|