setup_once_context 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +20 -0
- data/VERSION +1 -0
- data/lib/setup_once_context.rb +83 -0
- metadata +67 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Pratik Naik
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
SetupOnceContext
|
2
|
+
===========
|
3
|
+
|
4
|
+
Make your shoulda contexts faster by combining the 'should' blocks (e.g. setup is called only once).
|
5
|
+
|
6
|
+
See http://m.onkey.org/2009/9/20/make-your-shoulda-tests-faster-with-fast_context for details.
|
7
|
+
|
8
|
+
Installation
|
9
|
+
============
|
10
|
+
|
11
|
+
Step 1 : Install the plugin
|
12
|
+
|
13
|
+
$ script/plugin install git://github.com/jpfuentes2/setup_once_context.git
|
14
|
+
|
15
|
+
Step 2 : Require setup_once_context from the test helper
|
16
|
+
|
17
|
+
# RAILS_ROOT/test/test_helper.rb
|
18
|
+
require 'setup_once_context'
|
19
|
+
|
20
|
+
Copyright (c) 2009 Pratik Naik, released under the MIT license
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'shoulda/context'
|
2
|
+
|
3
|
+
module ShouldaContextExtensions
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
alias_method_chain :build, :setup_once_context
|
7
|
+
alias_method_chain :am_subcontext?, :setup_once_context
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup_once_context(name, &blk)
|
12
|
+
@setup_once_contexts ||= []
|
13
|
+
@setup_once_contexts << Shoulda::SetupOnceContext.new(name, self, &blk)
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_with_setup_once_context
|
17
|
+
build_without_setup_once_context
|
18
|
+
@setup_once_contexts ||= []
|
19
|
+
@setup_once_contexts.each {|f| f.build }
|
20
|
+
end
|
21
|
+
|
22
|
+
def am_subcontext_with_setup_once_context?
|
23
|
+
parent.is_a?(Shoulda::Context) || parent.is_a?(Shoulda::SetupOnceContext)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Shoulda
|
28
|
+
class SetupOnceContext < Context
|
29
|
+
def create_test_from_should_hash
|
30
|
+
test_name = ["test:", full_name, "should", "run_fast"].flatten.join(' ').to_sym
|
31
|
+
|
32
|
+
if test_unit_class.instance_methods.include?(test_name.to_s)
|
33
|
+
warn " * WARNING: '#{test_name}' is already defined"
|
34
|
+
end
|
35
|
+
|
36
|
+
context = self
|
37
|
+
test_unit_class.send(:define_method, test_name) do
|
38
|
+
@shoulda_context = context
|
39
|
+
@current_should = nil
|
40
|
+
begin
|
41
|
+
context.run_parent_setup_blocks(self)
|
42
|
+
context.shoulds.each do |s|
|
43
|
+
@current_should = s
|
44
|
+
s[:before].bind(self).call if s[:before]
|
45
|
+
end
|
46
|
+
context.run_current_setup_blocks(self)
|
47
|
+
|
48
|
+
context.shoulds.each {|should| should[:block].bind(self).call }
|
49
|
+
rescue Test::Unit::AssertionFailedError => e
|
50
|
+
error = Test::Unit::AssertionFailedError.new(["FAILED:", context.full_name, "should", "#{@current_should[:name]}:", e.message].flatten.join(' '))
|
51
|
+
error.set_backtrace e.backtrace
|
52
|
+
raise error
|
53
|
+
ensure
|
54
|
+
context.run_all_teardown_blocks(self)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def build
|
60
|
+
create_test_from_should_hash
|
61
|
+
subcontexts.each {|context| context.build }
|
62
|
+
|
63
|
+
@setup_once_contexts ||= []
|
64
|
+
@setup_once_contexts.each {|f| f.build }
|
65
|
+
|
66
|
+
print_should_eventuallys
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class ActiveSupport::TestCase
|
72
|
+
def self.setup_once_context(name, &blk)
|
73
|
+
if Shoulda.current_context
|
74
|
+
Shoulda.current_context.fast_context(name, &blk)
|
75
|
+
else
|
76
|
+
context = Shoulda::SetupOnceContext.new(name, self, &blk)
|
77
|
+
context.build
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Shoulda::Context.send :include, ShouldaContextExtensions
|
83
|
+
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: setup_once_context
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Pratik Naik
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-29 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Make your shoulda contexts faster by combining the 'should' blocks (e.g. setup is called only once).
|
22
|
+
email: jpfuentes2@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README
|
29
|
+
files:
|
30
|
+
- MIT-LICENSE
|
31
|
+
- README
|
32
|
+
- VERSION
|
33
|
+
- lib/setup_once_context.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/jpfuentes2/setup_once_context
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.7
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Improve test performance by executing setups only once.
|
66
|
+
test_files: []
|
67
|
+
|