nutrasuite 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +75 -0
- data/Rakefile +1 -0
- data/lib/nutrasuite/contexts.rb +122 -0
- data/lib/nutrasuite/version.rb +3 -0
- data/lib/nutrasuite.rb +3 -0
- data/nutrasuite.gemspec +24 -0
- metadata +56 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Nutrasuite
|
2
|
+
A low-calorie sweetener for your minitests.
|
3
|
+
|
4
|
+
## Purpose
|
5
|
+
|
6
|
+
We really like using Minitest, and really didn't like the fact that
|
7
|
+
contexts for your tests weren't built in. So we wrote Nutrasuite.
|
8
|
+
|
9
|
+
### OH NO ANOTHER TEST FRAMEWORK WHY ARGHUBUGAJKGAaSDFAWEGSGA
|
10
|
+
|
11
|
+
Nope. Just something to make working with minitest a little easier.
|
12
|
+
|
13
|
+
### Why don't you just use RSpec or Minitest::Spec?
|
14
|
+
|
15
|
+
Because monkeying with the object namespace just to write tests makes us feel dirty in all the wrong ways.
|
16
|
+
|
17
|
+
### Why don't you just use shoulda-context?
|
18
|
+
|
19
|
+
Because it pretty much seems to have been deprecated, so we'd rather take a few
|
20
|
+
minutes to put something together that we can maintain.
|
21
|
+
|
22
|
+
### Why haven't you used [something else]?
|
23
|
+
|
24
|
+
Because we haven't heard of it, or it didn't work, or it wasn't available as a
|
25
|
+
proper gem anymore.
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Although there may be some more niceties added in the future, right now
|
30
|
+
Nutrasuite is all about contexts. Write your tests like so:
|
31
|
+
|
32
|
+
require 'nutrasuite'
|
33
|
+
class SomeTest < MiniTest::Unit::TestCase
|
34
|
+
a "newly instantiated test object" do
|
35
|
+
setup do
|
36
|
+
some_setup_stuff
|
37
|
+
end
|
38
|
+
|
39
|
+
it "tests for stuff" do
|
40
|
+
assert true
|
41
|
+
end
|
42
|
+
|
43
|
+
teardown do
|
44
|
+
some_teardown_stuff
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
All of your other minitest stuff should work normally. Context
|
50
|
+
setup/teardown is executed once for each test, so the randomization built into
|
51
|
+
minitest will still work as you'd expect.
|
52
|
+
|
53
|
+
## Get it
|
54
|
+
|
55
|
+
It's a gem named nutrasuite. Install it and make it available however
|
56
|
+
you prefer.
|
57
|
+
|
58
|
+
## Contributions
|
59
|
+
|
60
|
+
If Nutrasuite interests you and you think you might want to contribute, hit me up
|
61
|
+
over Github. You can also just fork it and make some changes, but there's a
|
62
|
+
better chance that your work won't be duplicated or rendered obsolete if you
|
63
|
+
check in on the current development status first.
|
64
|
+
Gem requirements/etc. should be handled by Bundler.
|
65
|
+
|
66
|
+
### Contributors
|
67
|
+
|
68
|
+
Alan Johnson (commondream)
|
69
|
+
|
70
|
+
## License
|
71
|
+
Copyright (C) 2012 by Tommy Morgan
|
72
|
+
|
73
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
74
|
+
|
75
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Nutrasuite
|
2
|
+
module ContextHelpers
|
3
|
+
def a(name, &block)
|
4
|
+
name = "a " << name
|
5
|
+
Context.push(name, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def an(name, &block)
|
9
|
+
name = "an " << name
|
10
|
+
Context.push(name, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def and(name, &block)
|
14
|
+
name = "and " << name
|
15
|
+
Context.push(name, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def that(name, &block)
|
19
|
+
name = "that " << name
|
20
|
+
Context.push(name, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Code to be run before the context
|
24
|
+
def setup(&block)
|
25
|
+
if Context.current_context?
|
26
|
+
Context.current_context.setups << block
|
27
|
+
else
|
28
|
+
warn "Not in a context"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Code to be run when the context is finished
|
33
|
+
def teardown(&block)
|
34
|
+
if Context.current_context?
|
35
|
+
Context.current_context.teardowns << block
|
36
|
+
else
|
37
|
+
warn "Not in a context"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Defines an actual test based on the given context
|
42
|
+
def it(name, &block)
|
43
|
+
build_test(name, &block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_test(name, &block)
|
47
|
+
test_name = Context.build_test_name(name)
|
48
|
+
|
49
|
+
setups = []
|
50
|
+
teardowns = []
|
51
|
+
Context.context_stack.each do |context|
|
52
|
+
setups.concat(context.setups)
|
53
|
+
teardowns.concat(context.teardowns)
|
54
|
+
end
|
55
|
+
|
56
|
+
define_method test_name do
|
57
|
+
setups.each { |setup| setup.call }
|
58
|
+
block.call
|
59
|
+
teardowns.each { |teardown| teardown.call }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def warn(message)
|
64
|
+
puts " * Warning: #{message}"
|
65
|
+
end
|
66
|
+
|
67
|
+
include MiniTest::Assertions
|
68
|
+
end
|
69
|
+
|
70
|
+
class Context
|
71
|
+
include ContextHelpers
|
72
|
+
|
73
|
+
attr_reader :name, :setups, :teardowns
|
74
|
+
|
75
|
+
def initialize(name, &block)
|
76
|
+
@name = name
|
77
|
+
@block = block
|
78
|
+
|
79
|
+
@setups = []
|
80
|
+
@teardowns = []
|
81
|
+
end
|
82
|
+
|
83
|
+
def build
|
84
|
+
@block.call
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.build_test_name(name="")
|
88
|
+
full_name = "test "
|
89
|
+
@context_stack.each do |context|
|
90
|
+
full_name << context.name << " "
|
91
|
+
end
|
92
|
+
full_name << name
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.push(name, &block)
|
96
|
+
@context_stack ||= []
|
97
|
+
|
98
|
+
context = Context.new(name, &block)
|
99
|
+
@context_stack.push(context)
|
100
|
+
|
101
|
+
context.build
|
102
|
+
|
103
|
+
@context_stack.pop
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.context_stack
|
107
|
+
@context_stack
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.current_context
|
111
|
+
@context_stack.last
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.current_context?
|
115
|
+
!@context_stack.empty?
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class MiniTest::Unit::TestCase
|
121
|
+
extend Nutrasuite::ContextHelpers
|
122
|
+
end
|
data/lib/nutrasuite.rb
ADDED
data/nutrasuite.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "nutrasuite/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "nutrasuite"
|
7
|
+
s.version = Nutrasuite::VERSION
|
8
|
+
s.authors = ["Tommy Morgan","Alan Johnson"]
|
9
|
+
s.email = ["tommy.morgan@gmail.com","alan@commondream.net"]
|
10
|
+
s.homepage = "http://github.com/duwanis/nutrasuite"
|
11
|
+
s.summary = %q{Nutrasuite is a low-calorie syntax sweetener for minitest}
|
12
|
+
s.description = %q{Nutrasuite is a low-calorie syntax sweetener for minitest}
|
13
|
+
|
14
|
+
s.rubyforge_project = "nutrasuite"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nutrasuite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tommy Morgan
|
9
|
+
- Alan Johnson
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-02-19 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Nutrasuite is a low-calorie syntax sweetener for minitest
|
16
|
+
email:
|
17
|
+
- tommy.morgan@gmail.com
|
18
|
+
- alan@commondream.net
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- Gemfile
|
25
|
+
- README.markdown
|
26
|
+
- Rakefile
|
27
|
+
- lib/nutrasuite.rb
|
28
|
+
- lib/nutrasuite/contexts.rb
|
29
|
+
- lib/nutrasuite/version.rb
|
30
|
+
- nutrasuite.gemspec
|
31
|
+
homepage: http://github.com/duwanis/nutrasuite
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project: nutrasuite
|
51
|
+
rubygems_version: 1.8.15
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Nutrasuite is a low-calorie syntax sweetener for minitest
|
55
|
+
test_files: []
|
56
|
+
has_rdoc:
|