-
Notifications
You must be signed in to change notification settings - Fork 4
Getting Started
Create factory_girl factories remotely using remote_factory_girl in conjuction with remote_factory_girl_home_rails. Overcoming the problem with integration testing SOA apps
remote_factory_girl should live in the client application and remote_factory_girl_home_rails should live in the home app (the app with factory_girl factories).
Add this line to the client application's Gemfile:
group :test do
gem 'remote_factory_girl'
end
And then execute:
$ bundle
Or install it yourself as:
$ gem install remote_factory_girl
Configure in spec/spec_helper.rb
RemoteFactoryGirl.configure do |config|
config.home = { host: 'localhost', port: 5000, end_point: '/remote_factory_girl' }
config.return_with_root = false
config.return_response_as = :dot_notation
end
Use in specs
require 'spec_helper'
describe User do
it 'should create a user factory in RemoteFactoryGirlHome' do
user = RemoteFactoryGirl.create(:user, first_name: 'Sam', last_name: 'Iam')
expect(user.first_name).to eq('Sam')
end
end
If your apps are configured to use ActiveResource, then have remote_factory_girl return ActiveResource objects.
Configure in spec/spec_helper.rb
RemoteFactoryGirl.configure do |config|
config.home = { host: 'localhost', port: 5000, end_point: '/remote_factory_girl' }
config.return_as_active_resource = true
end
See remote_database_cleaner for installation and configuration
Configure in spec/spec_helper.rb
RSpec.configure do |config|
config.after(:before) do
RemoteDatabaseCleaner.clean
end
end
Use in specs
require 'spec_helper'
describe User do
it 'should create a user factory in RemoteFactoryGirlHome' do
user = RemoteFactoryGirl.create(:user_with_friends, first_name: 'Sam', last_name: 'Iam').resource(User)
expect(user.first_name).to eq('Sam')
end
end
Add this line to home application's Gemfile:
group :test do
gem 'remote_factory_girl_home_rails'
end
And then execute:
$ bundle
Configure in config/environments/*.rb
Activate remote_factory_girl_home_rails to run in the environments in which it is intended to
run. For example, if remote_factory_girl_home_rails is included in group :test
(most common), then activate it in config/environments/test.rb
YourApplication::Application.configure do
...
config.remote_factory_girl_home_rails.enable = true
...
end
Configure in config/routes.rb
YourApplication::Application.routes.draw do
if defined?(RemoteFactoryGirlHomeRails::Engine)
mount RemoteFactoryGirlHomeRails::Engine, at: '/remote_factory_girl'
end
end
Configure in config/initializers/remote_factory_girl_home_rails.rb
Specify any methods that should be skipped for incoming http requests. The most
common methods to skip are authentication related methods that live in
ApplicationController
.
RemoteFactoryGirlHomeRails.configure do |config|
config.skip_before_filter = [:authenticate, :some_other_method]
end if defined?(RemoteFactoryGirlHomeRails)
- Run any outstanding migrations.
- Start the home application's server with the correct:
- environment
- port
- end_point
Given the configuration from the examples above, start the home server with:
$ rails server --environment=test --pid=/Users/your_app/tmp/pids/your_app-test.pid --port=5000
- Run your test suite.
$ rspec