fast_context 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/MIT-LICENSE +20 -0
- data/README +20 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/lib/fast_context.rb +89 -0
- data/lib/init.rb +1 -0
- metadata +79 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.idea/*
|
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
|
+
FastContext
|
2
|
+
===========
|
3
|
+
|
4
|
+
Make your shoulda contexts faster by combining the 'should' blocks.
|
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/lifo/fast_context.git
|
14
|
+
|
15
|
+
Step 2 : Require fast_context from the test helper
|
16
|
+
|
17
|
+
# RAILS_ROOT/test/test_helper.rb
|
18
|
+
require 'fast_context'
|
19
|
+
|
20
|
+
Copyright (c) 2009 Pratik Naik, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "fast_context"
|
5
|
+
gemspec.summary = "This is a gem version of the fast_context plugin"
|
6
|
+
gemspec.email = "adam@pohorecki.pl"
|
7
|
+
gemspec.homepage = "http://github.com/psyho/fast_context"
|
8
|
+
gemspec.authors = ["Pratik Naik"]
|
9
|
+
gemspec.add_dependency 'shoulda'
|
10
|
+
end
|
11
|
+
rescue LoadError
|
12
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
13
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/lib/fast_context.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'shoulda/context'
|
2
|
+
|
3
|
+
module ShouldaContextExtensions
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
alias_method_chain :build, :fast_context
|
7
|
+
alias_method_chain :am_subcontext?, :fast_context
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def fast_context(name, &blk)
|
12
|
+
@fast_subcontexts ||= []
|
13
|
+
@fast_subcontexts << Shoulda::FastContext.new(name, self, &blk)
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_with_fast_context
|
17
|
+
build_without_fast_context
|
18
|
+
@fast_subcontexts ||= []
|
19
|
+
@fast_subcontexts.each {|f| f.build }
|
20
|
+
end
|
21
|
+
|
22
|
+
def am_subcontext_with_fast_context?
|
23
|
+
parent.is_a?(Shoulda::Context) || parent.is_a?(Shoulda::FastContext)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Shoulda
|
28
|
+
class FastContext < Context
|
29
|
+
def test_method_name
|
30
|
+
joined_should_name = shoulds.collect{ |should_hash| should_hash[:name] }.join(' and ')
|
31
|
+
test_name = ["test", full_name, "should", joined_should_name].flatten.join('_')
|
32
|
+
test_name = test_name.gsub(' ', '_').gsub(/[^a-zA-Z0-9_?!]/, '').gsub(/__+/, '_').to_sym
|
33
|
+
return test_name
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_test_from_should_hash
|
37
|
+
test_name = test_method_name
|
38
|
+
|
39
|
+
if test_unit_class.instance_methods.include?(test_name.to_s)
|
40
|
+
warn " * WARNING: '#{test_name}' is already defined"
|
41
|
+
end
|
42
|
+
|
43
|
+
context = self
|
44
|
+
test_unit_class.send(:define_method, test_name) do
|
45
|
+
@shoulda_context = context
|
46
|
+
@current_should = nil
|
47
|
+
begin
|
48
|
+
context.run_parent_setup_blocks(self)
|
49
|
+
context.shoulds.each do |s|
|
50
|
+
@current_should = s
|
51
|
+
s[:before].bind(self).call if s[:before]
|
52
|
+
end
|
53
|
+
context.run_current_setup_blocks(self)
|
54
|
+
|
55
|
+
context.shoulds.each {|should| should[:block].bind(self).call }
|
56
|
+
rescue Test::Unit::AssertionFailedError => e
|
57
|
+
error = Test::Unit::AssertionFailedError.new(["FAILED:", context.full_name, "should", "#{@current_should[:name]}:", e.message].flatten.join(' '))
|
58
|
+
error.set_backtrace e.backtrace
|
59
|
+
raise error
|
60
|
+
ensure
|
61
|
+
context.run_all_teardown_blocks(self)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def build
|
67
|
+
create_test_from_should_hash
|
68
|
+
subcontexts.each {|context| context.build }
|
69
|
+
|
70
|
+
@fast_subcontexts ||= []
|
71
|
+
@fast_subcontexts.each {|f| f.build }
|
72
|
+
|
73
|
+
print_should_eventuallys
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class ActiveSupport::TestCase
|
79
|
+
def self.fast_context(name, &blk)
|
80
|
+
if Shoulda.current_context
|
81
|
+
Shoulda.current_context.fast_context(name, &blk)
|
82
|
+
else
|
83
|
+
context = Shoulda::FastContext.new(name, self, &blk)
|
84
|
+
context.build
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
Shoulda::Context.send :include, ShouldaContextExtensions
|
data/lib/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'fast_context'))
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_context
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Pratik Naik
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-22 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
description:
|
33
|
+
email: adam@pohorecki.pl
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- README
|
40
|
+
files:
|
41
|
+
- .gitignore
|
42
|
+
- MIT-LICENSE
|
43
|
+
- README
|
44
|
+
- Rakefile
|
45
|
+
- VERSION
|
46
|
+
- lib/fast_context.rb
|
47
|
+
- lib/init.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/psyho/fast_context
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.6
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: This is a gem version of the fast_context plugin
|
78
|
+
test_files: []
|
79
|
+
|