factory_group 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +11 -7
- data/README.md +41 -4
- data/factory_group.gemspec +3 -1
- data/lib/factory_group/exceptions/factory_group_not_defined.rb +8 -0
- data/lib/factory_group/version.rb +1 -1
- data/lib/factory_group.rb +7 -4
- data/spec/acceptance/factory_group_spec.rb +21 -0
- data/spec/factory_group/group_spec.rb +4 -0
- data/spec/factory_group_spec.rb +27 -7
- data/spec/spec_helper.rb +2 -0
- data/spec/support/macros/define_models.rb +44 -0
- metadata +37 -6
- data/spec/acceptance/group_spec.rb +0 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a5b075ad08aec90a1833979525f8efda8d27623c
         | 
| 4 | 
            +
              data.tar.gz: 270250ee6eafd5bd89e3eb295386b4d46b677a76
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a00dbec2642850445b7e493961b5d5f3f48fe7aace1649e6afbfa750ca606c059d3f323738ef1e0863cc1bf58cb41272fd4785b0d317f5fff9a378d368cbb08f
         | 
| 7 | 
            +
              data.tar.gz: 45e8252f2a4de6b35fd28e3262307908ad91ca553bffa4c6f7a3d857f4be41b718614ca22b2c0e3036a906b35c6967f32de65c20ffe1717b7aa8f65cd4b3a3cd
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.travis.yml
    CHANGED
    
    | @@ -1,11 +1,15 @@ | |
| 1 1 | 
             
            rvm:
         | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 2 | 
            +
            - 2.1.0
         | 
| 3 | 
            +
            - 2.0.0-p481
         | 
| 4 | 
            +
            - 1.9.3
         | 
| 5 5 | 
             
            before_install:
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            install:  | 
| 8 | 
            -
            script:  | 
| 6 | 
            +
            - gem update --system
         | 
| 7 | 
            +
            install: bundle install
         | 
| 8 | 
            +
            script: CODECLIMATE_REPO_TOKEN=d3636dec3241cd9be3710d4de49e56b5cba3e56cb682dd0025600b67209520b0
         | 
| 9 | 
            +
              bundle exec rspec spec/
         | 
| 9 10 | 
             
            branches:
         | 
| 10 11 | 
             
              only:
         | 
| 11 | 
            -
             | 
| 12 | 
            +
              - master
         | 
| 13 | 
            +
            notifications:
         | 
| 14 | 
            +
              slack:
         | 
| 15 | 
            +
                secure: OygKatLhjN4O5Y6Br7PzkqZan+SDoHVaxUJkN/msDY/oBVdobUeknm7hf8EmxTMan3AavsfoXwhdk0Cc/Fy6RYLHRVcBveZAtz4iF8WMu64ogmaP4qhf32AUHLa56iyv7Vn/dK3kStlKI+Ko29mDzglYMONzrU4Lq5iOV3RqgQ8=
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,14 +1,22 @@ | |
| 1 1 | 
             
            # FactoryGroup
         | 
| 2 2 |  | 
| 3 | 
            -
            [](http://badge.fury.io/rb/factory_group) | 
| 3 | 
            +
            [](http://badge.fury.io/rb/factory_group)
         | 
| 4 | 
            +
            [](https://travis-ci.org/Codebrahma/factory_group)
         | 
| 5 | 
            +
            [](https://codeclimate.com/github/Codebrahma/factory_group)
         | 
| 6 | 
            +
            [](https://gemnasium.com/Codebrahma/factory_group)
         | 
| 7 | 
            +
            [](https://codeclimate.com/github/Codebrahma/factory_group)
         | 
| 4 8 |  | 
| 5 | 
            -
             | 
| 9 | 
            +
            By [CodeBrahma](http://codebrahma.com).
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            FactoryGroup provides an abstraction on top of factory_girl, which will help you create reusable groups of factories which can be used across test cases.
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            For now we support only rails applications.
         | 
| 6 14 |  | 
| 7 15 | 
             
            ## Installation
         | 
| 8 16 |  | 
| 9 17 | 
             
            Add this line to your application's Gemfile:
         | 
| 10 18 |  | 
| 11 | 
            -
                gem 'factory_group'
         | 
| 19 | 
            +
                gem 'factory_group', :group => :test
         | 
| 12 20 |  | 
| 13 21 | 
             
            And then execute:
         | 
| 14 22 |  | 
| @@ -20,7 +28,36 @@ Or install it yourself as: | |
| 20 28 |  | 
| 21 29 | 
             
            ## Usage
         | 
| 22 30 |  | 
| 23 | 
            -
             | 
| 31 | 
            +
            Define a factory group
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            ```ruby
         | 
| 34 | 
            +
            # spec/factory_groups/user_group.rb
         | 
| 35 | 
            +
            FactoryGroup.define :user_group do
         | 
| 36 | 
            +
              user FactoryGirl.create(:user, :name => "Rajinikant")
         | 
| 37 | 
            +
            end
         | 
| 38 | 
            +
            ```
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            Next require the factory_groups folder from the spec_helper
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            ```ruby
         | 
| 43 | 
            +
            # spec/spec_helper.rb
         | 
| 44 | 
            +
            Dir["spec/factory_groups/**/*.rb"].each { |f| require File.expand_path(f) }
         | 
| 45 | 
            +
            ```
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            Now from your spec call ```FactoryGroup.create(:user_group)```
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            ```ruby
         | 
| 50 | 
            +
            # spec/user_spec.rb
         | 
| 51 | 
            +
            describe User do
         | 
| 52 | 
            +
              let(:user_group) { FactoryGroup.create(:user_group) }
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              context "#name" do
         | 
| 55 | 
            +
                it "returns Rajinikant" do
         | 
| 56 | 
            +
                  (user_group.user.name).to eq "Rajinikant"
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
            end
         | 
| 60 | 
            +
            ```
         | 
| 24 61 |  | 
| 25 62 | 
             
            ## Contributing
         | 
| 26 63 |  | 
    
        data/factory_group.gemspec
    CHANGED
    
    | @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| | |
| 9 9 | 
             
              spec.authors       = ["Yuvaraja Balamurugan"]
         | 
| 10 10 | 
             
              spec.email         = ["yuv.slm@gmail.com"]
         | 
| 11 11 | 
             
              spec.summary       = %q{Lets you create a group of factories}
         | 
| 12 | 
            -
              spec.description   = %q{ | 
| 12 | 
            +
              spec.description   = %q{FactoryGroup provides an abstraction on top of factory_girl, which will help you create reusable groups of factories which can be used across test cases.}
         | 
| 13 13 | 
             
              spec.homepage      = "http://codebrahma.com/factory_group/"
         | 
| 14 14 | 
             
              spec.license       = "MIT"
         | 
| 15 15 |  | 
| @@ -27,4 +27,6 @@ Gem::Specification.new do |spec| | |
| 27 27 | 
             
              spec.add_development_dependency "rake", ">= 10.3.1"
         | 
| 28 28 | 
             
              spec.add_development_dependency "debugger", "~> 1.6.8"
         | 
| 29 29 | 
             
              spec.add_development_dependency "simplecov", "~> 0.9.0"
         | 
| 30 | 
            +
              spec.add_development_dependency "sqlite3", "~> 1.3.9"
         | 
| 31 | 
            +
              spec.add_development_dependency "activerecord", "~> 4.1.6"
         | 
| 30 32 | 
             
            end
         | 
    
        data/lib/factory_group.rb
    CHANGED
    
    | @@ -1,5 +1,6 @@ | |
| 1 1 | 
             
            require "factory_group/version"
         | 
| 2 2 | 
             
            require "factory_group/group"
         | 
| 3 | 
            +
            require "factory_group/exceptions/factory_group_not_defined"
         | 
| 3 4 |  | 
| 4 5 | 
             
            module FactoryGroup
         | 
| 5 6 | 
             
              @registry = {}
         | 
| @@ -9,13 +10,15 @@ module FactoryGroup | |
| 9 10 | 
             
              end
         | 
| 10 11 |  | 
| 11 12 | 
             
              def self.define(name, &block)
         | 
| 12 | 
            -
                 | 
| 13 | 
            -
             | 
| 14 | 
            -
                 | 
| 13 | 
            +
                FactoryGroup.registry[name] = -> {
         | 
| 14 | 
            +
                  Group.new.tap{ |g| g.instance_eval(&block) }
         | 
| 15 | 
            +
                }
         | 
| 15 16 | 
             
              end
         | 
| 16 17 |  | 
| 17 18 | 
             
              def self.create(name)
         | 
| 18 | 
            -
                 | 
| 19 | 
            +
                raise Exceptions::FactoryGroupNotDefined if !registry[name]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                factory_group = registry[name].call
         | 
| 19 22 | 
             
                factory_group.factories
         | 
| 20 23 | 
             
              end
         | 
| 21 24 | 
             
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require "spec_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe FactoryGroup do
         | 
| 4 | 
            +
              before(:all) do
         | 
| 5 | 
            +
                described_class.define(:user_group) do
         | 
| 6 | 
            +
                  user FactoryGirl.create(:user)
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              context "#create" do
         | 
| 11 | 
            +
                before do
         | 
| 12 | 
            +
                  @user_group = FactoryGroup.create(:user_group)
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
                it "should create a factory_group with the factories" do
         | 
| 15 | 
            +
                  expect(@user_group).to be_a OpenStruct
         | 
| 16 | 
            +
                  expect(@user_group.user).to be_a User
         | 
| 17 | 
            +
                  expect(@user_group.user.name).to eq "sample"
         | 
| 18 | 
            +
                  expect(@user_group.user.age).to eq 20
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
    
        data/spec/factory_group_spec.rb
    CHANGED
    
    | @@ -2,15 +2,15 @@ require "spec_helper" | |
| 2 2 |  | 
| 3 3 | 
             
            describe FactoryGroup do
         | 
| 4 4 |  | 
| 5 | 
            -
              let(: | 
| 5 | 
            +
              let!(:factory_group_definition) do
         | 
| 6 6 | 
             
                FactoryGroup.define(:user_group) do
         | 
| 7 7 | 
             
                  user "A User"
         | 
| 8 8 | 
             
                end
         | 
| 9 9 | 
             
              end
         | 
| 10 10 |  | 
| 11 11 | 
             
              context "#define" do
         | 
| 12 | 
            -
                it "returns  | 
| 13 | 
            -
                  expect( | 
| 12 | 
            +
                it "returns a proc that evaluates the block passed to define method" do
         | 
| 13 | 
            +
                  expect(factory_group_definition).to be_an_instance_of Proc
         | 
| 14 14 | 
             
                end
         | 
| 15 15 |  | 
| 16 16 | 
             
                it "stores the created group in the registry" do
         | 
| @@ -19,12 +19,32 @@ describe FactoryGroup do | |
| 19 19 | 
             
              end
         | 
| 20 20 |  | 
| 21 21 | 
             
              context "#create" do
         | 
| 22 | 
            -
                 | 
| 23 | 
            -
                   | 
| 22 | 
            +
                context "when a group with the given name is defined" do
         | 
| 23 | 
            +
                  let(:user_group){ described_class.create(:user_group) }
         | 
| 24 | 
            +
                  it "returns the created FactoryGroup::Group instance" do
         | 
| 25 | 
            +
                    expect(user_group).to be_an_instance_of OpenStruct
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  it "can be used to access the user variable" do
         | 
| 29 | 
            +
                    expect(user_group.user).to eq "A User"
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                context "when a group with the given name is not defined" do
         | 
| 34 | 
            +
                  it "should raise and exception" do
         | 
| 35 | 
            +
                    expect{
         | 
| 36 | 
            +
                      described_class.create(:invalid_user_group)
         | 
| 37 | 
            +
                    }.to raise_exception(FactoryGroup::Exceptions::FactoryGroupNotDefined)
         | 
| 38 | 
            +
                  end
         | 
| 24 39 | 
             
                end
         | 
| 25 40 |  | 
| 26 | 
            -
                 | 
| 27 | 
            -
                   | 
| 41 | 
            +
                context "multiple group instances" do
         | 
| 42 | 
            +
                  let(:group_one){ described_class.create(:user_group) }
         | 
| 43 | 
            +
                  let(:group_two){ described_class.create(:user_group) }
         | 
| 44 | 
            +
                  it "should have different object ids" do
         | 
| 45 | 
            +
                    group_one.user = "Another user"
         | 
| 46 | 
            +
                    expect(group_one.user).not_to eq(group_two.user)
         | 
| 47 | 
            +
                  end
         | 
| 28 48 | 
             
                end
         | 
| 29 49 | 
             
              end
         | 
| 30 50 |  | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
| @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            require "active_record"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class User < ActiveRecord::Base
         | 
| 4 | 
            +
            end
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            FactoryGirl.define do
         | 
| 7 | 
            +
              factory :user do
         | 
| 8 | 
            +
                name "sample"
         | 
| 9 | 
            +
                age 20
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            module CreateTables
         | 
| 14 | 
            +
              def create_table(table_name, &block)
         | 
| 15 | 
            +
                connection = ActiveRecord::Base.connection
         | 
| 16 | 
            +
                connection.create_table(table_name, &block)
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def drop_table(table_name)
         | 
| 20 | 
            +
                connection = ActiveRecord::Base.connection
         | 
| 21 | 
            +
                connection.drop_table(table_name)
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            RSpec.configure do |config|
         | 
| 26 | 
            +
              include CreateTables
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              config.before(:all) do
         | 
| 29 | 
            +
                ActiveRecord::Base.establish_connection(
         | 
| 30 | 
            +
                  adapter:  'sqlite3',
         | 
| 31 | 
            +
                  database: File.join(File.dirname(__FILE__), 'test.db')
         | 
| 32 | 
            +
                )
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                create_table :users do |t|
         | 
| 35 | 
            +
                  t.string :name, limit: 60
         | 
| 36 | 
            +
                  t.integer :age
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
             | 
| 41 | 
            +
              config.after(:all) do
         | 
| 42 | 
            +
                drop_table :users
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: factory_group
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Yuvaraja Balamurugan
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-10-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: factory_girl
         | 
| @@ -94,8 +94,36 @@ dependencies: | |
| 94 94 | 
             
                - - ~>
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 96 | 
             
                    version: 0.9.0
         | 
| 97 | 
            -
             | 
| 98 | 
            -
               | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: sqlite3
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - ~>
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: 1.3.9
         | 
| 104 | 
            +
              type: :development
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - ~>
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: 1.3.9
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: activerecord
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - ~>
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: 4.1.6
         | 
| 118 | 
            +
              type: :development
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - ~>
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: 4.1.6
         | 
| 125 | 
            +
            description: FactoryGroup provides an abstraction on top of factory_girl, which will
         | 
| 126 | 
            +
              help you create reusable groups of factories which can be used across test cases.
         | 
| 99 127 | 
             
            email:
         | 
| 100 128 | 
             
            - yuv.slm@gmail.com
         | 
| 101 129 | 
             
            executables: []
         | 
| @@ -111,12 +139,14 @@ files: | |
| 111 139 | 
             
            - Rakefile
         | 
| 112 140 | 
             
            - factory_group.gemspec
         | 
| 113 141 | 
             
            - lib/factory_group.rb
         | 
| 142 | 
            +
            - lib/factory_group/exceptions/factory_group_not_defined.rb
         | 
| 114 143 | 
             
            - lib/factory_group/group.rb
         | 
| 115 144 | 
             
            - lib/factory_group/version.rb
         | 
| 116 | 
            -
            - spec/acceptance/ | 
| 145 | 
            +
            - spec/acceptance/factory_group_spec.rb
         | 
| 117 146 | 
             
            - spec/factory_group/group_spec.rb
         | 
| 118 147 | 
             
            - spec/factory_group_spec.rb
         | 
| 119 148 | 
             
            - spec/spec_helper.rb
         | 
| 149 | 
            +
            - spec/support/macros/define_models.rb
         | 
| 120 150 | 
             
            homepage: http://codebrahma.com/factory_group/
         | 
| 121 151 | 
             
            licenses:
         | 
| 122 152 | 
             
            - MIT
         | 
| @@ -142,7 +172,8 @@ signing_key: | |
| 142 172 | 
             
            specification_version: 4
         | 
| 143 173 | 
             
            summary: Lets you create a group of factories
         | 
| 144 174 | 
             
            test_files:
         | 
| 145 | 
            -
            - spec/acceptance/ | 
| 175 | 
            +
            - spec/acceptance/factory_group_spec.rb
         | 
| 146 176 | 
             
            - spec/factory_group/group_spec.rb
         | 
| 147 177 | 
             
            - spec/factory_group_spec.rb
         | 
| 148 178 | 
             
            - spec/spec_helper.rb
         | 
| 179 | 
            +
            - spec/support/macros/define_models.rb
         |