Created
September 20, 2009 17:31
-
-
Save lifo/189854 to your computer and use it in GitHub Desktop.
Revisions
-
lifo revised this gist
Sep 29, 2009 . 1 changed file with 1 addition and 72 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,72 +1 @@ http://github.com/lifo/fast_context -
lifo revised this gist
Sep 21, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -58,7 +58,7 @@ def build end end class ActiveSupport::TestCase def self.fast_context(name, &blk) if Shoulda.current_context Shoulda.current_context.fast_context(name, &blk) -
lifo revised this gist
Sep 20, 2009 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ module ShouldaContextExtensions def self.included(base) base.class_eval do alias_method_chain :build, :fast_context alias_method_chain :am_subcontext?, :fast_context end end @@ -15,6 +16,10 @@ def build_with_fast_context @fast_subcontexts ||= [] @fast_subcontexts.each {|f| f.build } end def am_subcontext_with_fast_context? parent.is_a?(Shoulda::Context) || parent.is_a?(Shoulda::FastContext) end end module Shoulda @@ -64,4 +69,4 @@ def self.fast_context(name, &blk) end end Shoulda::Context.send :include, ShouldaContextExtensions -
lifo created this gist
Sep 20, 2009 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ module ShouldaContextExtensions def self.included(base) base.class_eval do alias_method_chain :build, :fast_context end end def fast_context(name, &blk) @fast_subcontexts ||= [] @fast_subcontexts << Shoulda::FastContext.new(name, self, &blk) end def build_with_fast_context build_without_fast_context @fast_subcontexts ||= [] @fast_subcontexts.each {|f| f.build } end end module Shoulda class FastContext < Context def create_test_from_should_hash test_name = ["test:", full_name, "should", "run_fast"].flatten.join(' ').to_sym if test_unit_class.instance_methods.include?(test_name.to_s) warn " * WARNING: '#{test_name}' is already defined" end context = self test_unit_class.send(:define_method, test_name) do @shoulda_context = context begin context.run_parent_setup_blocks(self) context.shoulds.each {|s| s[:before].bind(self).call if s[:before] } context.run_current_setup_blocks(self) context.shoulds.each {|should| should[:block].bind(self).call } ensure context.run_all_teardown_blocks(self) end end end def build create_test_from_should_hash subcontexts.each {|context| context.build } @fast_subcontexts ||= [] @fast_subcontexts.each {|f| f.build } print_should_eventuallys end end end class ActionController::TestCase def self.fast_context(name, &blk) if Shoulda.current_context Shoulda.current_context.fast_context(name, &blk) else context = Shoulda::FastContext.new(name, self, &blk) context.build end end end Shoulda::Context.send :include, ShouldaContextExtensions