Permalink
Browse files

Converted tests to specs

  • Loading branch information...
jferris committed Apr 11, 2009
1 parent 8189770 commit 683aa43fabe878de6796af9ff8a21ad3af2aaa32
Showing with 1,424 additions and 1,518 deletions.
  1. +9 −13 Rakefile
  2. +29 −0 spec/factory_girl/aliases_spec.rb
  3. +25 −0 spec/factory_girl/attribute/association_spec.rb
  4. +39 −0 spec/factory_girl/attribute/dynamic_spec.rb
  5. +29 −0 spec/factory_girl/attribute/static_spec.rb
  6. +29 −0 spec/factory_girl/attribute_spec.rb
  7. +490 −0 spec/factory_girl/factory_spec.rb
  8. +52 −0 spec/factory_girl/proxy/attributes_for_spec.rb
  9. +73 −0 spec/factory_girl/proxy/build_spec.rb
  10. +83 −0 spec/factory_girl/proxy/create_spec.rb
  11. +55 −0 spec/factory_girl/proxy/stub_spec.rb
  12. +28 −0 spec/factory_girl/proxy_spec.rb
  13. +66 −0 spec/factory_girl/sequence_spec.rb
  14. +34 −0 spec/factory_girl/syntax/blueprint_spec.rb
  15. +57 −0 spec/factory_girl/syntax/generate_spec.rb
  16. +35 −0 spec/factory_girl/syntax/make_spec.rb
  17. +35 −0 spec/factory_girl/syntax/sham_spec.rb
  18. +236 −0 spec/integration_spec.rb
  19. 0 {test → spec}/models.rb
  20. +2 −0 spec/spec.opts
  21. +18 −0 spec/spec_helper.rb
  22. +0 −29 test/aliases_test.rb
  23. +0 −32 test/association_attribute_test.rb
  24. +0 −33 test/attribute_test.rb
  25. +0 −56 test/attributes_for_strategy_test.rb
  26. +0 −81 test/build_strategy_test.rb
  27. +0 −91 test/create_strategy_test.rb
  28. +0 −43 test/dynamic_attribute_test.rb
  29. +0 −471 test/factory_test.rb
  30. +0 −235 test/integration_test.rb
  31. +0 −76 test/sequence_test.rb
  32. +0 −33 test/static_attribute_test.rb
  33. +0 −33 test/strategy_test.rb
  34. +0 −61 test/stub_strategy_test.rb
  35. +0 −39 test/syntax/blueprint_test.rb
  36. +0 −63 test/syntax/generate_test.rb
  37. +0 −39 test/syntax/make_test.rb
  38. +0 −40 test/syntax/sham_test.rb
  39. +0 −50 test/test_helper.rb
View
@@ -1,26 +1,22 @@
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'rcov/rcovtask'
require 'date'
desc 'Default: run unit tests.'
task :default => :test
require 'spec/rake/spectask'
desc 'Test the factory_girl plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
desc 'Default: run the specs.'
task :default => :spec
Spec::Rake::SpecTask.new do |t|
t.spec_opts = ['--options', "spec/spec.opts"]
end
desc 'Performs code coverage on the factory_girl plugin.'
Rcov::RcovTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/*_test.rb']
t.test_files = FileList['spec/*_spec.rb']
t.verbose = true
end
@@ -48,9 +44,9 @@ spec = Gem::Specification.new do |s|
using factories - less error-prone, more explicit, and
all-around easier to work with than fixtures.}
s.files = FileList['[A-Z]*', 'lib/**/*.rb', 'test/**/*.rb']
s.files = FileList['[A-Z]*', 'lib/**/*.rb', 'spec/**/*.rb']
s.require_path = 'lib'
s.test_files = Dir[*['test/**/*_test.rb']]
s.test_files = Dir[*['spec/**/*_spec.rb']]
s.has_rdoc = true
s.extra_rdoc_files = ["README.rdoc"]
@@ -0,0 +1,29 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
describe Factory, "aliases" do
it "should include an attribute as an alias for itself by default" do
Factory.aliases_for(:test).should include(:test)
end
it "should include the root of a foreign key as an alias by default" do
Factory.aliases_for(:test_id).should include(:test)
end
it "should include an attribute's foreign key as an alias by default" do
Factory.aliases_for(:test).should include(:test_id)
end
describe "after adding an alias" do
before do
Factory.alias(/(.*)_suffix/, '\1')
end
it "should return the alias in the aliases list" do
Factory.aliases_for(:test_suffix).should include(:test)
end
end
end
@@ -0,0 +1,25 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
describe Factory::Attribute::Association do
before do
@name = :author
@factory = :user
@overrides = { :first_name => 'John' }
@attr = Factory::Attribute::Association.new(@name, @factory, @overrides)
end
it "should have a name" do
@attr.name.should == @name
end
it "should tell the proxy to associate when being added to a proxy" do
proxy = "proxy"
stub(proxy).associate
@attr.add_to(proxy)
proxy.should have_received.associate(@name, @factory, @overrides)
end
it "should convert names to symbols" do
Factory::Attribute::Association.new('name', :user, {}).name.should == :name
end
end
@@ -0,0 +1,39 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
describe Factory::Attribute::Dynamic do
before do
@name = :first_name
@block = lambda { 'value' }
@attr = Factory::Attribute::Dynamic.new(@name, @block)
end
it "should have a name" do
@attr.name.should == @name
end
it "should call the block to set a value" do
@proxy = "proxy"
stub(@proxy).set
@attr.add_to(@proxy)
@proxy.should have_received.set(@name, 'value')
end
it "should yield the proxy to the block when adding its value to a proxy" do
@block = lambda {|a| a }
@attr = Factory::Attribute::Dynamic.new(:user, @block)
@proxy = "proxy"
stub(@proxy).set
@attr.add_to(@proxy)
@proxy.should have_received.set(:user, @proxy)
end
it "should raise an error when defining an attribute writer" do
lambda {
Factory::Attribute::Dynamic.new('test=', nil)
}.should raise_error(Factory::AttributeDefinitionError)
end
it "should convert names to symbols" do
Factory::Attribute::Dynamic.new('name', nil).name.should == :name
end
end
@@ -0,0 +1,29 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
describe Factory::Attribute::Static do
before do
@name = :first_name
@value = 'John'
@attr = Factory::Attribute::Static.new(@name, @value)
end
it "should have a name" do
@attr.name.should == @name
end
it "should set its static value on a proxy" do
@proxy = "proxy"
mock(@proxy).set(@name, @value)
@attr.add_to(@proxy)
end
it "should raise an error when defining an attribute writer" do
lambda {
Factory::Attribute::Static.new('test=', nil)
}.should raise_error(Factory::AttributeDefinitionError)
end
it "should convert names to symbols" do
Factory::Attribute::Static.new('name', nil).name.should == :name
end
end
@@ -0,0 +1,29 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
describe Factory::Attribute do
before do
@name = :user
@attr = Factory::Attribute.new(@name)
end
it "should have a name" do
@attr.name.should == @name
end
it "should do nothing when being added to a proxy" do
@proxy = "proxy"
stub(@proxy).set
@attr.add_to(@proxy)
@proxy.should have_received.set.never
end
it "should raise an error when defining an attribute writer" do
lambda {
Factory::Attribute.new('test=')
}.should raise_error(Factory::AttributeDefinitionError)
end
it "should convert names to symbols" do
Factory::Attribute.new('name').name.should == :name
end
end
Oops, something went wrong.

0 comments on commit 683aa43

Please sign in to comment.