Permalink
Browse files

tests for adding traits

  • Loading branch information...
1 parent 7f32e5e commit 723218365083b2298ab145e04ed0ba5601d603f1 @guilhermesilveira guilhermesilveira committed Oct 26, 2010
Showing with 184 additions and 19 deletions.
  1. +9 −0 Gemfile
  2. +91 −0 Gemfile.lock
  3. +6 −10 Rakefile
  4. +15 −0 lib/respondie.rb
  5. +22 −0 lib/respondie/builder.rb
  6. +24 −0 spec/respondie/builder_spec.rb
  7. +15 −3 spec/respondie_spec.rb
  8. +2 −6 spec/spec_helper.rb
View
@@ -0,0 +1,9 @@
+# A sample Gemfile
+source :gemcutter
+#
+gem "rails", ">= 3.0.0"
+
+group :test do
+ gem "rspec-rails", ">= 2.0.0.beta.19"
+ gem "rcov"
+end
View
@@ -0,0 +1,91 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.0)
+ actionpack (= 3.0.0)
+ mail (~> 2.2.5)
+ actionpack (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4.1)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.12)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ arel (~> 1.0.0)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ activesupport (3.0.0)
+ arel (1.0.1)
+ activesupport (~> 3.0.0)
+ builder (2.1.2)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.4.1)
+ mail (2.2.5)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mime-types (1.16)
+ nokogiri (1.4.3.1)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.6)
+ rack (>= 1.0)
+ rails (3.0.0)
+ actionmailer (= 3.0.0)
+ actionpack (= 3.0.0)
+ activerecord (= 3.0.0)
+ activeresource (= 3.0.0)
+ activesupport (= 3.0.0)
+ bundler (~> 1.0.0)
+ railties (= 3.0.0)
+ railties (3.0.0)
+ actionpack (= 3.0.0)
+ activesupport (= 3.0.0)
+ rake (>= 0.8.4)
+ thor (~> 0.14.0)
+ rake (0.8.7)
+ rcov (0.9.8)
+ rspec (2.0.0.beta.19)
+ rspec-core (= 2.0.0.beta.19)
+ rspec-expectations (= 2.0.0.beta.19)
+ rspec-mocks (= 2.0.0.beta.19)
+ rspec-core (2.0.0.beta.19)
+ rspec-expectations (2.0.0.beta.19)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0.beta.19)
+ rspec-rails (2.0.0.beta.19)
+ rspec (= 2.0.0.beta.19)
+ webrat (>= 0.7.2.beta.1)
+ thor (0.14.0)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+ webrat (0.7.2.beta.1)
+ nokogiri (>= 1.2.0)
+ rack (>= 1.0)
+ rack-test (>= 0.5.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rails (>= 3.0.0)
+ rcov
+ rspec-rails (>= 2.0.0.beta.19)
View
@@ -18,16 +18,12 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end
-require 'spec/rake/spectask'
-Spec::Rake::SpecTask.new(:spec) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.spec_files = FileList['spec/**/*_spec.rb']
-end
-
-Spec::Rake::SpecTask.new(:rcov) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.pattern = 'spec/**/*_spec.rb'
- spec.rcov = true
+require 'rspec'
+require 'rspec/core'
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec) do |t|
+ # t.spec_files = FileList['spec_*.rb']
+ t.rspec_opts = ['--colour', '--format progress']
end
task :spec => :check_dependencies
View
@@ -0,0 +1,15 @@
+require 'action_controller'
+
+module Respondie
+
+ def use_trait(&block)
+ Respondie::Builder.new("Respondie::Trait::$trait$", self).instance_eval(&block)
+ end
+
+ alias_method :use_traits, :use_trait
+
+end
+
+ActionController::Base.extend Respondie
+
+require 'respondie/builder'
View
@@ -0,0 +1,22 @@
+class Respondie::Builder
+
+ def initialize(pattern, controller)
+ @pattern = pattern
+ custom = Class.new(ActionController::Responder)
+ controller.responder = custom
+ @responder = controller.responder
+ end
+
+ def method_missing(sym)
+ trait sym
+ end
+
+ private
+
+ def trait(sym)
+ type = @pattern.gsub(/\$trait\$/, sym.to_s.camelize)
+ @responder.send :include, type.constantize
+ self
+ end
+
+end
@@ -0,0 +1,24 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+class ProductsController
+ attr_accessor :responder
+end
+module Respondie
+ module Trait
+ module Cute
+ def is_cute?
+ true
+ end
+ end
+ end
+end
+
+describe Respondie::Builder do
+
+ it "should include a type into a responder" do
+ controller = ProductsController.new
+ Respondie::Builder.new("Respondie::Trait::$trait$", controller).instance_eval { cute }
+ controller.responder.instance_method(:is_cute?).should_not be_nil
+ end
+
+end
View
@@ -1,7 +1,19 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-describe "Respondie" do
- it "fails" do
- fail "hey buddy, you should probably rename this file and start specing for real"
+class ApplicationController < ActionController::Base
+end
+
+class MyController < ApplicationController
+end
+
+describe Respondie do
+
+ it "should enhance ActionController with its cute method" do
+ MyController.should respond_to(:use_trait)
+ end
+
+ it "should enhance ActionController with its cute plural method" do
+ MyController.should respond_to(:use_traits)
end
+
end
View
@@ -1,9 +1,5 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'respondie'
-require 'spec'
-require 'spec/autorun'
-
-Spec::Runner.configure do |config|
-
-end
+require 'rspec'
+require 'rspec/autorun'

0 comments on commit 7232183

Please sign in to comment.