-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit defeae0
Showing
11 changed files
with
905 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2011 [name of plugin creator] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
== ActiveFactory | ||
|
||
<em>A fixture replacement library. With it your specs will become more declarative, uniform and terse.</em> | ||
*feedback will be highly appreciated* | ||
|
||
- Google group[http://groups.google.com/group/active_factory] | ||
|
||
== Introduction | ||
|
||
ActiveFactory allows you declaratively define | ||
which objects you want to have in a database for your spec. | ||
You can also define associations between the objects and | ||
redefine default values. | ||
Additionally ActiveFactory automatically defines accessor methods for the objects. | ||
The scope of the methods is limited to current spec. So they will not affect you other specs. | ||
|
||
it "Task.incomplete returns only incomplete tasks" do | ||
models { project - tasks({:complete => 0}, {:complete => 1}) } | ||
|
||
project.tasks.incomplete.should == [tasks[0]] | ||
end | ||
|
||
it "project displays incomplete tasks" do | ||
models { my - project - task(:complete => 0) } | ||
|
||
visit project_path(project) | ||
|
||
page.should have_content task.title | ||
end | ||
|
||
These specs require the following configuration: | ||
|
||
class ActiveFactory::Define | ||
|
||
factory :my, :class => User do | ||
username "my_name" | ||
password "my_password" | ||
|
||
after_build { | ||
object.save! | ||
emulate_sign_in object | ||
} | ||
end | ||
|
||
factory :project do | ||
title { "Project#{index} title" } | ||
end | ||
|
||
factory :task do | ||
title { "Task#{index} title" } | ||
end | ||
end | ||
|
||
In the configuration you specify default attribute values for an object, | ||
and in a specific test you may reassign the values for the needs of the test. | ||
Optional block after_build specifies actions that should be done | ||
after object was initialized but before saving it. | ||
If you want to create by the same factory several objects with different values, | ||
you may use blocks. | ||
Method index in those blocks returns index of the object being created. | ||
|
||
== Installation | ||
|
||
ActiveFactory requires Rails 3 and RSpec 2. | ||
|
||
rails plugin install git@github.com:tarasevich/active_factory.git | ||
|
||
Then create file spec/support/define_factories.rb with content: | ||
|
||
require 'active_factory' | ||
RSpec::configure do |c| | ||
c.include ActiveFactory::API, :type => :controller | ||
c.include ActiveFactory::API, :type => :model | ||
c.include ActiveFactory::API, :type => :request | ||
end | ||
|
||
class ActiveFactory::Define | ||
factory :some_factory, :class => YourModelClass do | ||
some_attribute { "some value" } | ||
end | ||
end | ||
|
||
Now you can add you factories in ActiveFactory::Define class | ||
and use models {} block in your specs. | ||
|
||
_Copyright (c) 2010-2011 Alexey Tarasevich, released under the MIT license_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the active_factory plugin.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.libs << 'test' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
|
||
desc 'Generate documentation for the active_factory plugin.' | ||
Rake::RDocTask.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'ActiveFactory' | ||
rdoc.options << '--line-numbers' << '--inline-source' | ||
rdoc.rdoc_files.include('README.rdoc') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'active_factory' if Rails.env == 'test' |
Oops, something went wrong.