Skip to content
Browse files

add testsuite

  • Loading branch information...
1 parent 3d61734 commit cd0120c20a7833d1d000b43a9fc36b7224715441 @wireframe committed Oct 10, 2013
Showing with 83 additions and 0 deletions.
  1. +2 −0 .rspec
  2. +4 −0 Rakefile
  3. +2 −0 factory_girl_rspec.gemspec
  4. +10 −0 spec/factories/users.rb
  5. +47 −0 spec/factory_girl_rspec_spec.rb
  6. +6 −0 spec/models/user.rb
  7. +12 −0 spec/spec_helper.rb
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
4 Rakefile
@@ -1,2 +1,6 @@
require 'bundler'
Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec)
+task :default => :spec
View
2 factory_girl_rspec.gemspec
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'rspec', '>= 2.0'
s.add_runtime_dependency 'factory_girl', '>= 2.0'
+ s.add_development_dependency 'sqlite3'
+
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
View
10 spec/factories/users.rb
@@ -0,0 +1,10 @@
+FactoryGirl.define do
+ factory :user do
+ name 'John Doe'
+
+ trait :when_name_is_empty do
+ name nil
+ end
+
+ end
+end
View
47 spec/factory_girl_rspec_spec.rb
@@ -0,0 +1,47 @@
+require 'spec_helper'
+
+describe FactoryGirl::Rspec do
+ describe '.with' do
+ context 'with factory' do
+ with :user
+ it 'creates helper method' do
+ expect(user).to_not be_nil
+ end
+ end
+ context 'with traits' do
+ with :user, :when_name_is_empty
+ it 'creates helper method name with factory + traits' do
+ expect(user_when_name_is_empty).to_not be_nil
+ expect(user_when_name_is_empty.name).to be_nil
+ end
+ end
+ context 'with overridden properties' do
+ with :user, name: 'Bob'
+ it 'configures instance with overridden properties' do
+ expect(user.name).to eq 'Bob'
+ end
+ end
+ end
+
+ describe '.with!' do
+ context 'with factory' do
+ with! :user
+ it 'creates helper method' do
+ expect(user).to_not be_nil
+ end
+ end
+ context 'with traits' do
+ with! :user, :when_name_is_empty
+ it 'creates helper method name with factory + traits' do
+ expect(user_when_name_is_empty).to_not be_nil
+ expect(user_when_name_is_empty.name).to be_nil
+ end
+ end
+ context 'with overridden properties' do
+ with! :user, name: 'Bob'
+ it 'configures instance with overridden properties' do
+ expect(user.name).to eq 'Bob'
+ end
+ end
+ end
+end
View
6 spec/models/user.rb
@@ -0,0 +1,6 @@
+class User
+ attr_accessor :name
+
+ def save!
+ end
+end
View
12 spec/spec_helper.rb
@@ -0,0 +1,12 @@
+require 'factory_girl_rspec'
+require 'models/user'
+
+FactoryGirl.find_definitions
+
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+
+ config.order = 'random'
+end

0 comments on commit cd0120c

Please sign in to comment.
Something went wrong with that request. Please try again.