cucumber_factory 1.1.8 → 1.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/VERSION +1 -1
 - data/cucumber_factory.gemspec +5 -3
 - data/lib/cucumber_factory/factory.rb +13 -4
 - data/spec/app_root/app/models/job_offer.rb +3 -2
 - data/spec/app_root/app/models/machinist_model.rb +6 -0
 - data/spec/app_root/app/models/plain_ruby_class.rb +4 -0
 - data/spec/factory_spec.rb +25 -3
 - metadata +5 -3
 - data/spec/app_root/db/migrate/003_create_job_offers.rb +0 -14
 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            1. 
     | 
| 
      
 1 
     | 
    
         
            +
            1.2.0
         
     | 
    
        data/cucumber_factory.gemspec
    CHANGED
    
    | 
         @@ -5,7 +5,7 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = %q{cucumber_factory}
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "1. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "1.2.0"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["Henning Koch"]
         
     | 
| 
         @@ -26,7 +26,9 @@ Gem::Specification.new do |s| 
     | 
|
| 
       26 
26 
     | 
    
         
             
                 "lib/cucumber_factory/factory.rb",
         
     | 
| 
       27 
27 
     | 
    
         
             
                 "spec/app_root/app/controllers/application_controller.rb",
         
     | 
| 
       28 
28 
     | 
    
         
             
                 "spec/app_root/app/models/job_offer.rb",
         
     | 
| 
      
 29 
     | 
    
         
            +
                 "spec/app_root/app/models/machinist_model.rb",
         
     | 
| 
       29 
30 
     | 
    
         
             
                 "spec/app_root/app/models/movie.rb",
         
     | 
| 
      
 31 
     | 
    
         
            +
                 "spec/app_root/app/models/plain_ruby_class.rb",
         
     | 
| 
       30 
32 
     | 
    
         
             
                 "spec/app_root/app/models/user.rb",
         
     | 
| 
       31 
33 
     | 
    
         
             
                 "spec/app_root/config/boot.rb",
         
     | 
| 
       32 
34 
     | 
    
         
             
                 "spec/app_root/config/database.yml",
         
     | 
| 
         @@ -39,7 +41,6 @@ Gem::Specification.new do |s| 
     | 
|
| 
       39 
41 
     | 
    
         
             
                 "spec/app_root/config/routes.rb",
         
     | 
| 
       40 
42 
     | 
    
         
             
                 "spec/app_root/db/migrate/001_create_movies.rb",
         
     | 
| 
       41 
43 
     | 
    
         
             
                 "spec/app_root/db/migrate/002_create_users.rb",
         
     | 
| 
       42 
     | 
    
         
            -
                 "spec/app_root/db/migrate/003_create_job_offers.rb",
         
     | 
| 
       43 
44 
     | 
    
         
             
                 "spec/app_root/lib/console_with_fixtures.rb",
         
     | 
| 
       44 
45 
     | 
    
         
             
                 "spec/app_root/log/.gitignore",
         
     | 
| 
       45 
46 
     | 
    
         
             
                 "spec/app_root/script/console",
         
     | 
| 
         @@ -56,6 +57,8 @@ Gem::Specification.new do |s| 
     | 
|
| 
       56 
57 
     | 
    
         
             
              s.test_files = [
         
     | 
| 
       57 
58 
     | 
    
         
             
                "spec/app_root/app/models/movie.rb",
         
     | 
| 
       58 
59 
     | 
    
         
             
                 "spec/app_root/app/models/job_offer.rb",
         
     | 
| 
      
 60 
     | 
    
         
            +
                 "spec/app_root/app/models/machinist_model.rb",
         
     | 
| 
      
 61 
     | 
    
         
            +
                 "spec/app_root/app/models/plain_ruby_class.rb",
         
     | 
| 
       59 
62 
     | 
    
         
             
                 "spec/app_root/app/models/user.rb",
         
     | 
| 
       60 
63 
     | 
    
         
             
                 "spec/app_root/app/controllers/application_controller.rb",
         
     | 
| 
       61 
64 
     | 
    
         
             
                 "spec/app_root/config/environment.rb",
         
     | 
| 
         @@ -67,7 +70,6 @@ Gem::Specification.new do |s| 
     | 
|
| 
       67 
70 
     | 
    
         
             
                 "spec/app_root/config/boot.rb",
         
     | 
| 
       68 
71 
     | 
    
         
             
                 "spec/app_root/config/routes.rb",
         
     | 
| 
       69 
72 
     | 
    
         
             
                 "spec/app_root/db/migrate/002_create_users.rb",
         
     | 
| 
       70 
     | 
    
         
            -
                 "spec/app_root/db/migrate/003_create_job_offers.rb",
         
     | 
| 
       71 
73 
     | 
    
         
             
                 "spec/app_root/db/migrate/001_create_movies.rb",
         
     | 
| 
       72 
74 
     | 
    
         
             
                 "spec/app_root/lib/console_with_fixtures.rb",
         
     | 
| 
       73 
75 
     | 
    
         
             
                 "spec/factory_spec.rb",
         
     | 
| 
         @@ -49,7 +49,7 @@ module Cucumber 
     | 
|
| 
       49 
49 
     | 
    
         
             
                      attribute = fragment[1].gsub(" ", "_").to_sym
         
     | 
| 
       50 
50 
     | 
    
         
             
                      value_type = fragment[2] # 'above' or a quoted string
         
     | 
| 
       51 
51 
     | 
    
         
             
                      value = fragment[3]
         
     | 
| 
       52 
     | 
    
         
            -
                      association = model_class.reflect_on_association(attribute)
         
     | 
| 
      
 52 
     | 
    
         
            +
                      association = model_class.reflect_on_association(attribute) if model_class.respond_to?(:reflect_on_association)
         
     | 
| 
       53 
53 
     | 
    
         
             
                      if association.present?
         
     | 
| 
       54 
54 
     | 
    
         
             
                        if value_type == "above"
         
     | 
| 
       55 
55 
     | 
    
         
             
                          value = association.klass.last or raise "There is no last #{attribute}"
         
     | 
| 
         @@ -75,12 +75,21 @@ module Cucumber 
     | 
|
| 
       75 
75 
     | 
    
         
             
                end
         
     | 
| 
       76 
76 
     | 
    
         | 
| 
       77 
77 
     | 
    
         
             
                private
         
     | 
| 
      
 78 
     | 
    
         
            +
                
         
     | 
| 
      
 79 
     | 
    
         
            +
                def self.factory_girl_factory_name(model_class)
         
     | 
| 
      
 80 
     | 
    
         
            +
                  model_class.to_s.underscore.to_sym
         
     | 
| 
      
 81 
     | 
    
         
            +
                end
         
     | 
| 
       78 
82 
     | 
    
         | 
| 
       79 
83 
     | 
    
         
             
                def self.create_record(model_class, attributes)
         
     | 
| 
       80 
     | 
    
         
            -
                   
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
      
 84 
     | 
    
         
            +
                  factory_name = factory_girl_factory_name(model_class)
         
     | 
| 
      
 85 
     | 
    
         
            +
                  if defined?(::Factory) && factory = ::Factory.factories[factory_name]
         
     | 
| 
      
 86 
     | 
    
         
            +
                    ::Factory.create(factory_name, attributes)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  else
         
     | 
| 
      
 88 
     | 
    
         
            +
                    create_method = [:make, :create!, :new].detect do |method_name|
         
     | 
| 
      
 89 
     | 
    
         
            +
                      model_class.respond_to? method_name
         
     | 
| 
      
 90 
     | 
    
         
            +
                    end
         
     | 
| 
      
 91 
     | 
    
         
            +
                    model_class.send(create_method, attributes)
         
     | 
| 
       82 
92 
     | 
    
         
             
                  end
         
     | 
| 
       83 
     | 
    
         
            -
                  model_class.send(create_method, attributes)
         
     | 
| 
       84 
93 
     | 
    
         
             
                end
         
     | 
| 
       85 
94 
     | 
    
         | 
| 
       86 
95 
     | 
    
         
             
              end
         
     | 
    
        data/spec/factory_spec.rb
    CHANGED
    
    | 
         @@ -1,5 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require File.dirname(__FILE__) + '/spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            class Factory # for factory_girl compatibility spec
         
     | 
| 
      
 4 
     | 
    
         
            +
              def self.factories
         
     | 
| 
      
 5 
     | 
    
         
            +
                {}
         
     | 
| 
      
 6 
     | 
    
         
            +
              end  
         
     | 
| 
      
 7 
     | 
    
         
            +
            end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       3 
9 
     | 
    
         
             
            describe Cucumber::Factory do
         
     | 
| 
       4 
10 
     | 
    
         | 
| 
       5 
11 
     | 
    
         
             
              describe 'add_steps' do
         
     | 
| 
         @@ -41,13 +47,29 @@ describe Cucumber::Factory do 
     | 
|
| 
       41 
47 
     | 
    
         
             
                  @world = Object.new
         
     | 
| 
       42 
48 
     | 
    
         
             
                end
         
     | 
| 
       43 
49 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                it "should create  
     | 
| 
      
 50 
     | 
    
         
            +
                it "should create ActiveRecord models by calling #create!" do
         
     | 
| 
       45 
51 
     | 
    
         
             
                  Movie.should_receive(:create!).with({})
         
     | 
| 
       46 
52 
     | 
    
         
             
                  Cucumber::Factory.parse(@world, "Given there is a movie")
         
     | 
| 
       47 
53 
     | 
    
         
             
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
                
         
     | 
| 
      
 55 
     | 
    
         
            +
                it "should create models that have a machinist blueprint by calling #make" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                  MachinistModel.should_receive(:make).with({ :attribute => "foo"})
         
     | 
| 
      
 57 
     | 
    
         
            +
                  Cucumber::Factory.parse(@world, 'Given there is a machinist model with the attribute "foo"')
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
                
         
     | 
| 
      
 60 
     | 
    
         
            +
                it "should create models that have a factory_girl factory by calling #Factory.make(:model_name)" do
         
     | 
| 
      
 61 
     | 
    
         
            +
                  Factory.should_receive(:factories).with().and_return({ :job_offer => :job_offer_factory }) # Fake factory look up in factory_girl
         
     | 
| 
      
 62 
     | 
    
         
            +
                  Factory.should_receive(:create).with(:job_offer, { :title => "Awesome job" })
         
     | 
| 
      
 63 
     | 
    
         
            +
                  Cucumber::Factory.parse(@world, 'Given there is a job offer with the title "Awesome job"')
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
                
         
     | 
| 
      
 66 
     | 
    
         
            +
                it "should instantiate plain ruby classes by calling #new" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  PlainRubyClass.should_receive(:new).with({})
         
     | 
| 
      
 68 
     | 
    
         
            +
                  Cucumber::Factory.parse(@world, "Given there is a plain ruby class")
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
       48 
70 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
                it "should  
     | 
| 
       50 
     | 
    
         
            -
                  JobOffer.should_receive(: 
     | 
| 
      
 71 
     | 
    
         
            +
                it "should instantiate classes with multiple words in their name" do
         
     | 
| 
      
 72 
     | 
    
         
            +
                  JobOffer.should_receive(:new).with({})
         
     | 
| 
       51 
73 
     | 
    
         
             
                  Cucumber::Factory.parse(@world, "Given there is a job offer")
         
     | 
| 
       52 
74 
     | 
    
         
             
                end
         
     | 
| 
       53 
75 
     | 
    
         | 
    
        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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Henning Koch
         
     | 
| 
         @@ -32,7 +32,9 @@ files: 
     | 
|
| 
       32 
32 
     | 
    
         
             
            - lib/cucumber_factory/factory.rb
         
     | 
| 
       33 
33 
     | 
    
         
             
            - spec/app_root/app/controllers/application_controller.rb
         
     | 
| 
       34 
34 
     | 
    
         
             
            - spec/app_root/app/models/job_offer.rb
         
     | 
| 
      
 35 
     | 
    
         
            +
            - spec/app_root/app/models/machinist_model.rb
         
     | 
| 
       35 
36 
     | 
    
         
             
            - spec/app_root/app/models/movie.rb
         
     | 
| 
      
 37 
     | 
    
         
            +
            - spec/app_root/app/models/plain_ruby_class.rb
         
     | 
| 
       36 
38 
     | 
    
         
             
            - spec/app_root/app/models/user.rb
         
     | 
| 
       37 
39 
     | 
    
         
             
            - spec/app_root/config/boot.rb
         
     | 
| 
       38 
40 
     | 
    
         
             
            - spec/app_root/config/database.yml
         
     | 
| 
         @@ -45,7 +47,6 @@ files: 
     | 
|
| 
       45 
47 
     | 
    
         
             
            - spec/app_root/config/routes.rb
         
     | 
| 
       46 
48 
     | 
    
         
             
            - spec/app_root/db/migrate/001_create_movies.rb
         
     | 
| 
       47 
49 
     | 
    
         
             
            - spec/app_root/db/migrate/002_create_users.rb
         
     | 
| 
       48 
     | 
    
         
            -
            - spec/app_root/db/migrate/003_create_job_offers.rb
         
     | 
| 
       49 
50 
     | 
    
         
             
            - spec/app_root/lib/console_with_fixtures.rb
         
     | 
| 
       50 
51 
     | 
    
         
             
            - spec/app_root/log/.gitignore
         
     | 
| 
       51 
52 
     | 
    
         
             
            - spec/app_root/script/console
         
     | 
| 
         @@ -84,6 +85,8 @@ summary: Create records from Cucumber features without writing step definitions. 
     | 
|
| 
       84 
85 
     | 
    
         
             
            test_files: 
         
     | 
| 
       85 
86 
     | 
    
         
             
            - spec/app_root/app/models/movie.rb
         
     | 
| 
       86 
87 
     | 
    
         
             
            - spec/app_root/app/models/job_offer.rb
         
     | 
| 
      
 88 
     | 
    
         
            +
            - spec/app_root/app/models/machinist_model.rb
         
     | 
| 
      
 89 
     | 
    
         
            +
            - spec/app_root/app/models/plain_ruby_class.rb
         
     | 
| 
       87 
90 
     | 
    
         
             
            - spec/app_root/app/models/user.rb
         
     | 
| 
       88 
91 
     | 
    
         
             
            - spec/app_root/app/controllers/application_controller.rb
         
     | 
| 
       89 
92 
     | 
    
         
             
            - spec/app_root/config/environment.rb
         
     | 
| 
         @@ -95,7 +98,6 @@ test_files: 
     | 
|
| 
       95 
98 
     | 
    
         
             
            - spec/app_root/config/boot.rb
         
     | 
| 
       96 
99 
     | 
    
         
             
            - spec/app_root/config/routes.rb
         
     | 
| 
       97 
100 
     | 
    
         
             
            - spec/app_root/db/migrate/002_create_users.rb
         
     | 
| 
       98 
     | 
    
         
            -
            - spec/app_root/db/migrate/003_create_job_offers.rb
         
     | 
| 
       99 
101 
     | 
    
         
             
            - spec/app_root/db/migrate/001_create_movies.rb
         
     | 
| 
       100 
102 
     | 
    
         
             
            - spec/app_root/lib/console_with_fixtures.rb
         
     | 
| 
       101 
103 
     | 
    
         
             
            - spec/factory_spec.rb
         
     |