cucumber_factory 1.1.7 → 1.1.8

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/README.rdoc CHANGED
@@ -5,11 +5,11 @@ Cucumber Factory allows you to create ActiveRecord objects directly from your {C
5
5
  == Installation
6
6
 
7
7
  Install the gem:
8
- sudo gem sources -a http://gems.github.com
9
- sudo gem install makandra-cucumber_factory
8
+ sudo gem sources -a http://gemcutter.org
9
+ sudo gem install 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 'makandra-cucumber_factory', :lib => 'cucumber_factory', :source => 'http://gems.github.com'
12
+ config.gem 'cucumber_factory', :source => 'http://gemcutter.org'
13
13
 
14
14
  Create a step definition stub in <tt>features/step_definitions/factory_steps.rb</tt>, which just says
15
15
  Cucumber::Factory.add_steps(self)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.7
1
+ 1.1.8
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{cucumber_factory}
5
- s.version = "1.1.7"
8
+ s.version = "1.1.8"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Henning Koch"]
9
- s.date = %q{2009-09-18}
12
+ s.date = %q{2009-11-16}
10
13
  s.description = %q{Cucumber Factory allows you to create ActiveRecord models from your Cucumber features without writing step definitions for each model.}
11
14
  s.email = %q{github@makandra.de}
12
15
  s.extra_rdoc_files = [
@@ -22,6 +25,7 @@ Gem::Specification.new do |s|
22
25
  "lib/cucumber_factory.rb",
23
26
  "lib/cucumber_factory/factory.rb",
24
27
  "spec/app_root/app/controllers/application_controller.rb",
28
+ "spec/app_root/app/models/job_offer.rb",
25
29
  "spec/app_root/app/models/movie.rb",
26
30
  "spec/app_root/app/models/user.rb",
27
31
  "spec/app_root/config/boot.rb",
@@ -35,6 +39,7 @@ Gem::Specification.new do |s|
35
39
  "spec/app_root/config/routes.rb",
36
40
  "spec/app_root/db/migrate/001_create_movies.rb",
37
41
  "spec/app_root/db/migrate/002_create_users.rb",
42
+ "spec/app_root/db/migrate/003_create_job_offers.rb",
38
43
  "spec/app_root/lib/console_with_fixtures.rb",
39
44
  "spec/app_root/log/.gitignore",
40
45
  "spec/app_root/script/console",
@@ -43,14 +48,14 @@ Gem::Specification.new do |s|
43
48
  "spec/spec.opts",
44
49
  "spec/spec_helper.rb"
45
50
  ]
46
- s.has_rdoc = true
47
51
  s.homepage = %q{http://github.com/makandra/cucumber_factory}
48
52
  s.rdoc_options = ["--charset=UTF-8"]
49
53
  s.require_paths = ["lib"]
50
- s.rubygems_version = %q{1.3.1}
54
+ s.rubygems_version = %q{1.3.5}
51
55
  s.summary = %q{Create records from Cucumber features without writing step definitions.}
52
56
  s.test_files = [
53
57
  "spec/app_root/app/models/movie.rb",
58
+ "spec/app_root/app/models/job_offer.rb",
54
59
  "spec/app_root/app/models/user.rb",
55
60
  "spec/app_root/app/controllers/application_controller.rb",
56
61
  "spec/app_root/config/environment.rb",
@@ -62,6 +67,7 @@ Gem::Specification.new do |s|
62
67
  "spec/app_root/config/boot.rb",
63
68
  "spec/app_root/config/routes.rb",
64
69
  "spec/app_root/db/migrate/002_create_users.rb",
70
+ "spec/app_root/db/migrate/003_create_job_offers.rb",
65
71
  "spec/app_root/db/migrate/001_create_movies.rb",
66
72
  "spec/app_root/lib/console_with_fixtures.rb",
67
73
  "spec/factory_spec.rb",
@@ -70,7 +76,7 @@ Gem::Specification.new do |s|
70
76
 
71
77
  if s.respond_to? :specification_version then
72
78
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
73
- s.specification_version = 2
79
+ s.specification_version = 3
74
80
 
75
81
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
76
82
  else
@@ -36,12 +36,12 @@ module Cucumber
36
36
 
37
37
  def self.parse_named_creation(world, name, raw_model, raw_attributes)
38
38
  record = parse_creation(world, raw_model, raw_attributes)
39
- variable = variable_name(name)
39
+ variable = variable_name_from_prose(name)
40
40
  world.instance_variable_set variable, record
41
41
  end
42
42
 
43
43
  def self.parse_creation(world, raw_model, raw_attributes)
44
- model_class = raw_model.camelize.constantize
44
+ model_class = model_class_from_prose(raw_model)
45
45
  attributes = {}
46
46
  if raw_attributes.present? && raw_attributes.strip.present?
47
47
  raw_attributes.scan(/(the|and|with| )+(.*?) ("([^\"]*)"|above)/).each do |fragment|
@@ -54,7 +54,7 @@ module Cucumber
54
54
  if value_type == "above"
55
55
  value = association.klass.last or raise "There is no last #{attribute}"
56
56
  else
57
- value = world.instance_variable_get(variable_name(value))
57
+ value = world.instance_variable_get(variable_name_from_prose(value))
58
58
  end
59
59
  end
60
60
  attributes[attribute] = value
@@ -63,7 +63,11 @@ module Cucumber
63
63
  create_record(model_class, attributes)
64
64
  end
65
65
 
66
- def self.variable_name(prose)
66
+ def self.model_class_from_prose(prose)
67
+ prose.gsub(/[^a-z0-9_]+/, "_").camelize.constantize
68
+ end
69
+
70
+ def self.variable_name_from_prose(prose)
67
71
  name = prose.downcase.gsub(/[^a-z0-9_]+/, '_')
68
72
  name = name.gsub(/^_+/, '').gsub(/_+$/, '')
69
73
  name = "_#{name}" unless name.length >= 0 && name =~ /^[a-z]/
@@ -0,0 +1,3 @@
1
+ class JobOffer < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,14 @@
1
+ class CreateJobOffers < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :job_offers do |t|
5
+ t.string :title
6
+ t.string :skill
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :job_offers
12
+ end
13
+
14
+ end
data/spec/factory_spec.rb CHANGED
@@ -11,17 +11,26 @@ describe Cucumber::Factory do
11
11
  end
12
12
 
13
13
  end
14
+
15
+ describe 'model_class_from_prose' do
16
+
17
+ it "should return the class matching a natural language expression" do
18
+ Cucumber::Factory.model_class_from_prose("movie").should == Movie
19
+ Cucumber::Factory.model_class_from_prose("job offer").should == JobOffer
20
+ end
14
21
 
15
- describe 'variable_name' do
22
+ end
23
+
24
+ describe 'variable_name_from_prose' do
16
25
 
17
26
  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'
27
+ Cucumber::Factory.variable_name_from_prose("movie").should == :'@movie'
28
+ Cucumber::Factory.variable_name_from_prose("Some Movie").should == :'@some_movie'
20
29
  end
21
30
 
22
31
  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 == :'@_'
32
+ Cucumber::Factory.variable_name_from_prose("1973").should == :'@_1973'
33
+ Cucumber::Factory.variable_name_from_prose("%$§").should == :'@_'
25
34
  end
26
35
 
27
36
  end
@@ -36,6 +45,11 @@ describe Cucumber::Factory do
36
45
  Movie.should_receive(:create!).with({})
37
46
  Cucumber::Factory.parse(@world, "Given there is a movie")
38
47
  end
48
+
49
+ it "should create records for classes with multiple words" do
50
+ JobOffer.should_receive(:create!).with({})
51
+ Cucumber::Factory.parse(@world, "Given there is a job offer")
52
+ end
39
53
 
40
54
  it "should create records with attributes" do
41
55
  Movie.should_receive(:create!).with({ :title => "Sunshine", :year => "2007" })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-18 00:00:00 +02:00
12
+ date: 2009-11-16 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -31,6 +31,7 @@ files:
31
31
  - lib/cucumber_factory.rb
32
32
  - lib/cucumber_factory/factory.rb
33
33
  - spec/app_root/app/controllers/application_controller.rb
34
+ - spec/app_root/app/models/job_offer.rb
34
35
  - spec/app_root/app/models/movie.rb
35
36
  - spec/app_root/app/models/user.rb
36
37
  - spec/app_root/config/boot.rb
@@ -44,6 +45,7 @@ files:
44
45
  - spec/app_root/config/routes.rb
45
46
  - spec/app_root/db/migrate/001_create_movies.rb
46
47
  - spec/app_root/db/migrate/002_create_users.rb
48
+ - spec/app_root/db/migrate/003_create_job_offers.rb
47
49
  - spec/app_root/lib/console_with_fixtures.rb
48
50
  - spec/app_root/log/.gitignore
49
51
  - spec/app_root/script/console
@@ -77,10 +79,11 @@ requirements: []
77
79
  rubyforge_project:
78
80
  rubygems_version: 1.3.5
79
81
  signing_key:
80
- specification_version: 2
82
+ specification_version: 3
81
83
  summary: Create records from Cucumber features without writing step definitions.
82
84
  test_files:
83
85
  - spec/app_root/app/models/movie.rb
86
+ - spec/app_root/app/models/job_offer.rb
84
87
  - spec/app_root/app/models/user.rb
85
88
  - spec/app_root/app/controllers/application_controller.rb
86
89
  - spec/app_root/config/environment.rb
@@ -92,6 +95,7 @@ test_files:
92
95
  - spec/app_root/config/boot.rb
93
96
  - spec/app_root/config/routes.rb
94
97
  - spec/app_root/db/migrate/002_create_users.rb
98
+ - spec/app_root/db/migrate/003_create_job_offers.rb
95
99
  - spec/app_root/db/migrate/001_create_movies.rb
96
100
  - spec/app_root/lib/console_with_fixtures.rb
97
101
  - spec/factory_spec.rb