Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added some basic specs.

  • Loading branch information...
commit 565481aadbf9a95d5ac88eb54665c81c5d0019fc 1 parent adc2385
@notahat notahat authored
View
1  .gitignore
@@ -0,0 +1 @@
+coverage
View
13 README.markdown
@@ -0,0 +1,13 @@
+Machinist
+=========
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+
+Copyright (c) 2008 Peter Yandell, released under the MIT license
View
12 Rakefile
@@ -0,0 +1,12 @@
+require 'rake'
+require 'spec/rake/spectask'
+
+desc 'Default: run specs.'
+task :default => :spec
+
+desc 'Run all the specs for the machinist plugin.'
+Spec::Rake::SpecTask.new do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_opts = ['--colour']
+ t.rcov = true
+end
View
2  lib/machinist.rb
@@ -1,3 +1,5 @@
+require 'active_support'
+
module Machinist
def self.included(base)
base.extend(ClassMethods)
View
59 spec/machinist_spec.rb
@@ -0,0 +1,59 @@
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
+require 'machinist'
+
+class Base
+ include Machinist
+
+ def save!
+ true
+ end
+
+ def reload
+ self
+ end
+end
+
+class Post < Base
+ attr_accessor :title
+ attr_accessor :body
+end
+
+class Comment < Base
+ attr_accessor :post
+ attr_accessor :author
+ attr_accessor :body
+end
+
+Post.blueprint do
+ title "An Example Post"
+ body { "The quick brown fox." }
+end
+
+Comment.blueprint do
+ post
+ author "Fred Bloggs"
+ body "Just a comment."
+end
+
+describe Machinist do
+ it "should set a field from a constant in the blueprint" do
+ post = Post.make
+ post.title.should == "An Example Post"
+ end
+
+ it "should set a field from a block in the blueprint" do
+ post = Post.make
+ post.body.should == "The quick brown fox."
+ end
+
+ it "should overrid a field from the blueprint with a parameter" do
+ post = Post.make(:title => "A Different Title")
+ post.title.should == "A Different Title"
+ end
+
+ it "should create an associated object for a field with no arguments in the blueprint" do
+ comment = Comment.make
+ comment.post.should_not be_nil
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.