rspec_outlines 0.0.1 → 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/CHANGELOG +7 -0
- data/README.markdown +124 -0
- data/Rakefile +1 -57
- data/features/step_definitions/spec_steps.rb +18 -0
- data/features/support/env.rb +16 -0
- data/lib/rspec_outlines.rb +141 -9
- data/lib/rspec_outlines/version.rb +11 -0
- metadata +52 -56
- data/.document +0 -5
- data/.gitignore +0 -5
- data/DESCRIPTION.txt +0 -12
- data/README.rdoc +0 -18
- data/VERSION +0 -1
- data/lib/rspec_outlines/error.rb +0 -3
- data/lib/rspec_outlines/example_group.rb +0 -28
- data/lib/rspec_outlines/example_methods.rb +0 -19
- data/lib/rspec_outlines/example_proxy.rb +0 -5
- data/lib/rspec_outlines/outline.rb +0 -23
- data/rspec_outlines.gemspec +0 -81
- data/spec/example_group_spec.rb +0 -80
- data/spec/example_methods_spec.rb +0 -46
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -14
- data/spec_integration/integration_spec.rb +0 -32
- data/spec_integration/spec.opts +0 -3
- data/spec_integration/spec_files/should_not_affect_normal_specs.rb +0 -11
- data/spec_integration/spec_files/should_run_the_outline_for_each_set_of_values_given.rb +0 -13
data/CHANGELOG
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# RSpec Outlines
|
2
|
+
|
3
|
+
Cuke-style scenario outlines for RSpec.
|
4
|
+
|
5
|
+
## Example
|
6
|
+
|
7
|
+
describe "Adding three numbers" do
|
8
|
+
outline "should return the sum" do
|
9
|
+
(a + b + c).should == result
|
10
|
+
end
|
11
|
+
|
12
|
+
fields :a, :b, :c, :result
|
13
|
+
values 1, 1, 2, 4
|
14
|
+
values -1, -2, -3, -6
|
15
|
+
values -1, 1, 0, 0
|
16
|
+
end
|
17
|
+
|
18
|
+
This defines 3 examples. Each one consists of the block given to `outline`, with
|
19
|
+
`a`, `b`, and `c` set to the values given in the table below it. Easy, huh?
|
20
|
+
|
21
|
+
Aside from being a more readable way to write repetitive specs, tables are a
|
22
|
+
great way to see that you've covered all the combinations of arguments you need
|
23
|
+
to test.
|
24
|
+
|
25
|
+
For example, suppose in the above example you want to ensure you've checked
|
26
|
+
using every combination of positive and negative arguments:
|
27
|
+
|
28
|
+
fields :a, :b, :c, :result
|
29
|
+
values 2, 3, 5, 10
|
30
|
+
values 2, 3, -5, 0
|
31
|
+
values 2, -3, 5, 4
|
32
|
+
values 2, -3, -5, -6
|
33
|
+
values -2, 3, 5, 6
|
34
|
+
values -2, 3, -5, -4
|
35
|
+
values -2, -3, 5, 0
|
36
|
+
values -2, -3, -5, -10
|
37
|
+
|
38
|
+
Now you can clearly see you've tested every combination.
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
As in the first example, use `outline` to define a spec outline, `fields` to
|
43
|
+
declare the variables, and `values` to create an example with the given values
|
44
|
+
bound to those variables.
|
45
|
+
|
46
|
+
There are also some tricks you can play with `outline`.
|
47
|
+
|
48
|
+
## Substitutions in example descriptions
|
49
|
+
|
50
|
+
Use `:foo` in the description of an outline to substitute the value `foo` from
|
51
|
+
the table:
|
52
|
+
|
53
|
+
outline ":a + :b + :c should be :result" do
|
54
|
+
(a + b + c).should == result
|
55
|
+
end
|
56
|
+
|
57
|
+
This will produce names like:
|
58
|
+
|
59
|
+
2 + 3 + 5 should be 10
|
60
|
+
|
61
|
+
This lets you keep your spec names descriptive and unique. You may also delimit
|
62
|
+
the field name in braces if you want to append something to a value. Example:
|
63
|
+
|
64
|
+
outline ":{controller_name}Controller works correctly"
|
65
|
+
|
66
|
+
Might produce names like:
|
67
|
+
|
68
|
+
UsersController works correctly
|
69
|
+
|
70
|
+
You can also interpolate a 1-based index using `:#`. Example:
|
71
|
+
|
72
|
+
outline "should return the sum (:#)" do
|
73
|
+
...
|
74
|
+
end
|
75
|
+
|
76
|
+
Will produce names:
|
77
|
+
|
78
|
+
should return the sum (1)
|
79
|
+
should return the sum (2)
|
80
|
+
should return the sum (3)
|
81
|
+
...
|
82
|
+
|
83
|
+
Useful when you just want to keep your spec names distinct, but don't care
|
84
|
+
enough to name them perfectly.
|
85
|
+
|
86
|
+
If your name does not contain any interpolations, RSpec Outlines will
|
87
|
+
automatically append `" (:#)"` to your outline name.
|
88
|
+
|
89
|
+
## Multiple examples per outline
|
90
|
+
|
91
|
+
If you omit the string argument to `outline`, the block will be evaluated at the
|
92
|
+
example group level.
|
93
|
+
|
94
|
+
describe "Adding or multiplying two numbers" do
|
95
|
+
outline do
|
96
|
+
it "should return the sum"
|
97
|
+
(a + b).should == sum
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return the product"
|
101
|
+
(a * b).should == product
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
fields :a, :b, :sum, :product
|
106
|
+
values 1, 1, 2, 1
|
107
|
+
values -1, -2, -3, 2
|
108
|
+
values -1, 1, 0, -1
|
109
|
+
end
|
110
|
+
|
111
|
+
This lets you define multiple specs inside the block, or use more elaborate
|
112
|
+
logic to compute the spec descriptions.
|
113
|
+
|
114
|
+
## Contributing
|
115
|
+
|
116
|
+
* [Bug reports](https://github.com/oggy/rspec_outlines/issues)
|
117
|
+
* [Source](https://github.com/oggy/rspec_outlines)
|
118
|
+
* Patches: Fork on Github, send pull request.
|
119
|
+
* Include tests where practical.
|
120
|
+
* Leave the version alone, or bump it in a separate commit.
|
121
|
+
|
122
|
+
## Copyright
|
123
|
+
|
124
|
+
Copyright (c) George Ogata. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,57 +1 @@
|
|
1
|
-
require '
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
ROOT = File.dirname(__FILE__)
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'jeweler'
|
8
|
-
Jeweler::Tasks.new do |gem|
|
9
|
-
gem.name = "rspec_outlines"
|
10
|
-
gem.summary = "Define specs in tables."
|
11
|
-
gem.description = File.read("#{ROOT}/DESCRIPTION.txt")
|
12
|
-
gem.email = "george.ogata@gmail.com"
|
13
|
-
gem.homepage = "http://github.com/oggy/rspec_outlines"
|
14
|
-
gem.authors = ["George Ogata"]
|
15
|
-
gem.add_development_dependency "rspec"
|
16
|
-
gem.add_development_dependency "mocha"
|
17
|
-
end
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
-
end
|
21
|
-
|
22
|
-
require 'spec/rake/spectask'
|
23
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
-
spec.libs << 'lib' << 'spec'
|
25
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
-
spec.spec_opts = ['--options', "#{ROOT}/spec/spec.opts"]
|
27
|
-
end
|
28
|
-
|
29
|
-
Spec::Rake::SpecTask.new(:spec_integration) do |spec|
|
30
|
-
spec.libs << 'lib' << 'spec'
|
31
|
-
spec.spec_files = FileList['spec_integration/integration_spec.rb']
|
32
|
-
spec.spec_opts = ['--options', "#{ROOT}/spec_integration/spec.opts"]
|
33
|
-
end
|
34
|
-
|
35
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
36
|
-
spec.libs << 'lib' << 'spec'
|
37
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
-
spec.rcov = true
|
39
|
-
end
|
40
|
-
|
41
|
-
task :spec => :check_dependencies
|
42
|
-
|
43
|
-
task :default => :spec
|
44
|
-
|
45
|
-
require 'rake/rdoctask'
|
46
|
-
Rake::RDocTask.new do |rdoc|
|
47
|
-
if File.exist?('VERSION')
|
48
|
-
version = File.read('VERSION')
|
49
|
-
else
|
50
|
-
version = ""
|
51
|
-
end
|
52
|
-
|
53
|
-
rdoc.rdoc_dir = 'rdoc'
|
54
|
-
rdoc.title = "rspec_outlines #{version}"
|
55
|
-
rdoc.rdoc_files.include('README*')
|
56
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
-
end
|
1
|
+
require 'ritual'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Given /^this specification:$/ do |content|
|
2
|
+
open("#{TMP}/spec.rb", 'w') do |file|
|
3
|
+
file.puts "require 'rspec_outlines'"
|
4
|
+
file.print content
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
When /^I run rspec on it$/ do
|
9
|
+
@output = `bundle exec rspec "#{TMP}/spec.rb" 2>&1`
|
10
|
+
end
|
11
|
+
|
12
|
+
When /^I run rspec with "(.*)" on it$/ do |args|
|
13
|
+
@output = `bundle exec rspec #{args} "#{TMP}/spec.rb" 2>&1`
|
14
|
+
end
|
15
|
+
|
16
|
+
Then /^the output should contain "(.*?)"$/ do |string|
|
17
|
+
@output.should include(string)
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'rspec/expectations'
|
3
|
+
require 'ruby-debug'
|
4
|
+
|
5
|
+
ROOT = File.dirname(File.dirname(File.dirname(__FILE__)))
|
6
|
+
TMP = "#{ROOT}/features/tmp"
|
7
|
+
|
8
|
+
Debugger.start
|
9
|
+
|
10
|
+
Before do
|
11
|
+
FileUtils.mkdir_p(TMP)
|
12
|
+
end
|
13
|
+
|
14
|
+
After do
|
15
|
+
FileUtils.rm_rf(TMP)
|
16
|
+
end
|
data/lib/rspec_outlines.rb
CHANGED
@@ -1,12 +1,144 @@
|
|
1
1
|
module RSpecOutlines
|
2
|
-
|
2
|
+
Error = Class.new(RuntimeError)
|
3
|
+
|
4
|
+
module ExampleGroup
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def outline(name=nil, &definition)
|
11
|
+
if name
|
12
|
+
outline_body = lambda { |x| it(outline_example_name(name), &definition) }
|
13
|
+
else
|
14
|
+
outline_body = definition
|
15
|
+
end
|
16
|
+
@current_outline = Outline.new(self, &outline_body)
|
17
|
+
@current_outline_example_counter = 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def current_outline
|
21
|
+
@current_outline ||= nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def fields(*names)
|
25
|
+
current_outline or
|
26
|
+
raise Error, "no outline defined"
|
27
|
+
current_outline.fields = names
|
28
|
+
end
|
29
|
+
|
30
|
+
def values(*args)
|
31
|
+
current_outline.eval(*args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def instance_eval_with_outline_binding(outline_binding, &block)
|
35
|
+
original_outline_binding = @current_outline_binding
|
36
|
+
@current_outline_binding = outline_binding
|
37
|
+
@current_outline_example_counter += 1
|
38
|
+
begin
|
39
|
+
instance_eval(&block)
|
40
|
+
ensure
|
41
|
+
@current_outline_binding = original_outline_binding
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def outline_example_name(name)
|
46
|
+
name = name.dup
|
47
|
+
changed = name.gsub!(/:(?:(\w+|#)|\{(\w+)\})/) do
|
48
|
+
field = $1 || $2
|
49
|
+
if field == '#'
|
50
|
+
current_outline_example_counter
|
51
|
+
else
|
52
|
+
current_outline_binding[field.to_sym]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
# Give specs have unique names by default.
|
56
|
+
changed ? name : outline_example_name("#{name} (:#)")
|
57
|
+
end
|
58
|
+
|
59
|
+
attr_reader :current_outline_binding, :current_outline_example_counter
|
60
|
+
end
|
61
|
+
|
62
|
+
def method_missing(name, *args)
|
63
|
+
outline_binding = example.outline_binding
|
64
|
+
if outline_binding && outline_binding.defined?(name)
|
65
|
+
args.empty? or
|
66
|
+
raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
|
67
|
+
outline_binding[name]
|
68
|
+
else
|
69
|
+
super
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
module Example
|
75
|
+
def self.included(base)
|
76
|
+
base.class_eval do
|
77
|
+
alias initialize_without_rspec_outlines initialize
|
78
|
+
alias initialize initialize_with_rspec_outlines
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def initialize_with_rspec_outlines(*args, &block)
|
83
|
+
initialize_without_rspec_outlines(*args, &block)
|
84
|
+
@outline_binding = @example_group_class.current_outline_binding
|
85
|
+
end
|
3
86
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
87
|
+
attr_reader :outline_binding
|
88
|
+
end
|
89
|
+
|
90
|
+
class Outline
|
91
|
+
def initialize(example_group, &definition)
|
92
|
+
@example_group = example_group
|
93
|
+
@definition = definition
|
94
|
+
@fields = nil
|
95
|
+
end
|
96
|
+
|
97
|
+
attr_reader :example_group, :fields, :definition
|
98
|
+
|
99
|
+
def fields=(fields)
|
100
|
+
@fields = fields.map { |v| v.to_sym }
|
101
|
+
end
|
102
|
+
|
103
|
+
def eval(*values)
|
104
|
+
fields or
|
105
|
+
raise Error, "no fields defined"
|
106
|
+
outline_binding = OutlineBinding.new(fields, values)
|
107
|
+
example_group.instance_eval_with_outline_binding(outline_binding, &definition)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class OutlineBinding
|
112
|
+
def initialize(names=[], values=[])
|
113
|
+
@fields = {}
|
114
|
+
merge!(names, values)
|
115
|
+
end
|
116
|
+
|
117
|
+
def merge(names, values)
|
118
|
+
names.length == values.length or
|
119
|
+
raise ArgumentError, "wrong number of values (#{fields.length} fields, #{values.length} values given)"
|
120
|
+
dup.merge!(names, values)
|
121
|
+
end
|
122
|
+
|
123
|
+
def defined?(name)
|
124
|
+
@fields.key?(name)
|
125
|
+
end
|
126
|
+
|
127
|
+
def [](name)
|
128
|
+
@fields[name]
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def merge!(names, values)
|
134
|
+
names.zip(values) do |name, value|
|
135
|
+
@fields[name] = value
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
attr_reader :fields
|
140
|
+
end
|
141
|
+
end
|
9
142
|
|
10
|
-
|
11
|
-
|
12
|
-
Spec::Example::ExampleProxy.send :include, RSpecOutlines::ExampleProxy
|
143
|
+
RSpec::Core::ExampleGroup.send :include, RSpecOutlines::ExampleGroup
|
144
|
+
RSpec::Core::Example.send :include, RSpecOutlines::Example
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_outlines
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- George Ogata
|
@@ -9,103 +10,98 @@ autorequire:
|
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date:
|
13
|
+
date: 2011-04-04 00:00:00 -04:00
|
13
14
|
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: rspec
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "2.0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ritual
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - "="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.3.0
|
17
36
|
type: :development
|
18
|
-
|
19
|
-
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: cucumber
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
20
43
|
requirements:
|
21
44
|
- - ">="
|
22
45
|
- !ruby/object:Gem::Version
|
23
46
|
version: "0"
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: mocha
|
27
47
|
type: :development
|
28
|
-
|
29
|
-
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: ruby-debug19
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
30
54
|
requirements:
|
31
55
|
- - ">="
|
32
56
|
- !ruby/object:Gem::Version
|
33
57
|
version: "0"
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
describe "Adding two numbers" do
|
39
|
-
outline "should return the sum" do
|
40
|
-
(a + b).should == c
|
41
|
-
end
|
42
|
-
|
43
|
-
fields :a, :b, :c
|
44
|
-
values 1, 1, 2
|
45
|
-
values 2, 3, 5
|
46
|
-
values 1, -1, 0
|
47
|
-
end
|
48
|
-
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
description:
|
49
61
|
email: george.ogata@gmail.com
|
50
62
|
executables: []
|
51
63
|
|
52
64
|
extensions: []
|
53
65
|
|
54
|
-
extra_rdoc_files:
|
55
|
-
|
56
|
-
- README.rdoc
|
66
|
+
extra_rdoc_files: []
|
67
|
+
|
57
68
|
files:
|
58
|
-
- .
|
59
|
-
- .
|
60
|
-
-
|
69
|
+
- lib/rspec_outlines/version.rb
|
70
|
+
- lib/rspec_outlines.rb
|
71
|
+
- CHANGELOG
|
61
72
|
- LICENSE
|
62
|
-
- README.rdoc
|
63
73
|
- Rakefile
|
64
|
-
-
|
65
|
-
-
|
66
|
-
-
|
67
|
-
- lib/rspec_outlines/example_group.rb
|
68
|
-
- lib/rspec_outlines/example_methods.rb
|
69
|
-
- lib/rspec_outlines/example_proxy.rb
|
70
|
-
- lib/rspec_outlines/outline.rb
|
71
|
-
- rspec_outlines.gemspec
|
72
|
-
- spec/example_group_spec.rb
|
73
|
-
- spec/example_methods_spec.rb
|
74
|
-
- spec/spec.opts
|
75
|
-
- spec/spec_helper.rb
|
76
|
-
- spec_integration/integration_spec.rb
|
77
|
-
- spec_integration/spec.opts
|
78
|
-
- spec_integration/spec_files/should_not_affect_normal_specs.rb
|
79
|
-
- spec_integration/spec_files/should_run_the_outline_for_each_set_of_values_given.rb
|
74
|
+
- README.markdown
|
75
|
+
- features/step_definitions/spec_steps.rb
|
76
|
+
- features/support/env.rb
|
80
77
|
has_rdoc: true
|
81
78
|
homepage: http://github.com/oggy/rspec_outlines
|
82
79
|
licenses: []
|
83
80
|
|
84
81
|
post_install_message:
|
85
|
-
rdoc_options:
|
86
|
-
|
82
|
+
rdoc_options: []
|
83
|
+
|
87
84
|
require_paths:
|
88
85
|
- lib
|
89
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
90
88
|
requirements:
|
91
89
|
- - ">="
|
92
90
|
- !ruby/object:Gem::Version
|
93
91
|
version: "0"
|
94
|
-
version:
|
95
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
96
94
|
requirements:
|
97
95
|
- - ">="
|
98
96
|
- !ruby/object:Gem::Version
|
99
97
|
version: "0"
|
100
|
-
version:
|
101
98
|
requirements: []
|
102
99
|
|
103
100
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.
|
101
|
+
rubygems_version: 1.6.2
|
105
102
|
signing_key:
|
106
103
|
specification_version: 3
|
107
|
-
summary:
|
104
|
+
summary: Cucumber scenario outlines for RSpec.
|
108
105
|
test_files:
|
109
|
-
-
|
110
|
-
-
|
111
|
-
- spec/spec_helper.rb
|
106
|
+
- features/step_definitions/spec_steps.rb
|
107
|
+
- features/support/env.rb
|
data/.document
DELETED
data/DESCRIPTION.txt
DELETED
data/README.rdoc
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
= rspec_outlines
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Note on Patches/Pull Requests
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but
|
13
|
-
bump version in a commit by itself I can ignore when I pull)
|
14
|
-
* Send me a pull request. Bonus points for topic branches.
|
15
|
-
|
16
|
-
== Copyright
|
17
|
-
|
18
|
-
Copyright (c) 2009 George Ogata. See LICENSE for details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.1
|
data/lib/rspec_outlines/error.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module RSpecOutlines
|
2
|
-
module ExampleGroup
|
3
|
-
def outline(name, &definition)
|
4
|
-
@current_outline = Outline.new(self, name, &definition)
|
5
|
-
end
|
6
|
-
|
7
|
-
def current_outline
|
8
|
-
@current_outline ||= nil
|
9
|
-
end
|
10
|
-
|
11
|
-
def fields(*names)
|
12
|
-
need_outline
|
13
|
-
current_outline.fields = names.map{|name| name.to_sym}
|
14
|
-
end
|
15
|
-
|
16
|
-
def values(*args)
|
17
|
-
need_outline
|
18
|
-
current_outline.instantiate(*args)
|
19
|
-
end
|
20
|
-
|
21
|
-
private # -------------------------------------------------------
|
22
|
-
|
23
|
-
def need_outline
|
24
|
-
current_outline or
|
25
|
-
raise Error, "no outline defined"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module RSpecOutlines
|
2
|
-
module ExampleMethods
|
3
|
-
def method_missing(name, *args)
|
4
|
-
if is_outline_field_name?(name) && args.empty?
|
5
|
-
lookup_outline_field_name(name)
|
6
|
-
else
|
7
|
-
super
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def is_outline_field_name?(name)
|
12
|
-
@_proxy.outline_values && @_proxy.outline_values.key?(name)
|
13
|
-
end
|
14
|
-
|
15
|
-
def lookup_outline_field_name(name)
|
16
|
-
@_proxy.outline_values[name]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module RSpecOutlines
|
2
|
-
class Outline
|
3
|
-
def initialize(example_group, name, &definition)
|
4
|
-
@example_group = example_group
|
5
|
-
@name = name
|
6
|
-
@definition = definition
|
7
|
-
@fields = nil
|
8
|
-
@number_of_examples = 0
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :name
|
12
|
-
attr_accessor :fields
|
13
|
-
|
14
|
-
def instantiate(*values)
|
15
|
-
fields or
|
16
|
-
raise Error, "no fields defined"
|
17
|
-
fields.length == values.length or
|
18
|
-
raise ArgumentError, "wrong number of values (#{fields.length} fields, #{values.length} values)"
|
19
|
-
example = @example_group.example("#{name} - #{@number_of_examples += 1}", &@definition)
|
20
|
-
example.outline_values = Hash[*fields.zip(values).flatten]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/rspec_outlines.gemspec
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{rspec_outlines}
|
8
|
-
s.version = "0.0.1"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["George Ogata"]
|
12
|
-
s.date = %q{2009-11-15}
|
13
|
-
s.description = %q{Cucumber outlines for RSpec!
|
14
|
-
|
15
|
-
describe "Adding two numbers" do
|
16
|
-
outline "should return the sum" do
|
17
|
-
(a + b).should == c
|
18
|
-
end
|
19
|
-
|
20
|
-
fields :a, :b, :c
|
21
|
-
values 1, 1, 2
|
22
|
-
values 2, 3, 5
|
23
|
-
values 1, -1, 0
|
24
|
-
end
|
25
|
-
}
|
26
|
-
s.email = %q{george.ogata@gmail.com}
|
27
|
-
s.extra_rdoc_files = [
|
28
|
-
"LICENSE",
|
29
|
-
"README.rdoc"
|
30
|
-
]
|
31
|
-
s.files = [
|
32
|
-
".document",
|
33
|
-
".gitignore",
|
34
|
-
"DESCRIPTION.txt",
|
35
|
-
"LICENSE",
|
36
|
-
"README.rdoc",
|
37
|
-
"Rakefile",
|
38
|
-
"VERSION",
|
39
|
-
"lib/rspec_outlines.rb",
|
40
|
-
"lib/rspec_outlines/error.rb",
|
41
|
-
"lib/rspec_outlines/example_group.rb",
|
42
|
-
"lib/rspec_outlines/example_methods.rb",
|
43
|
-
"lib/rspec_outlines/example_proxy.rb",
|
44
|
-
"lib/rspec_outlines/outline.rb",
|
45
|
-
"rspec_outlines.gemspec",
|
46
|
-
"spec/example_group_spec.rb",
|
47
|
-
"spec/example_methods_spec.rb",
|
48
|
-
"spec/spec.opts",
|
49
|
-
"spec/spec_helper.rb",
|
50
|
-
"spec_integration/integration_spec.rb",
|
51
|
-
"spec_integration/spec.opts",
|
52
|
-
"spec_integration/spec_files/should_not_affect_normal_specs.rb",
|
53
|
-
"spec_integration/spec_files/should_run_the_outline_for_each_set_of_values_given.rb"
|
54
|
-
]
|
55
|
-
s.homepage = %q{http://github.com/oggy/rspec_outlines}
|
56
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
57
|
-
s.require_paths = ["lib"]
|
58
|
-
s.rubygems_version = %q{1.3.5}
|
59
|
-
s.summary = %q{Define specs in tables.}
|
60
|
-
s.test_files = [
|
61
|
-
"spec/example_group_spec.rb",
|
62
|
-
"spec/example_methods_spec.rb",
|
63
|
-
"spec/spec_helper.rb"
|
64
|
-
]
|
65
|
-
|
66
|
-
if s.respond_to? :specification_version then
|
67
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
68
|
-
s.specification_version = 3
|
69
|
-
|
70
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
71
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
72
|
-
s.add_development_dependency(%q<mocha>, [">= 0"])
|
73
|
-
else
|
74
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
75
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
76
|
-
end
|
77
|
-
else
|
78
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
79
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
80
|
-
end
|
81
|
-
end
|
data/spec/example_group_spec.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RSpecOutlines::ExampleGroup do
|
4
|
-
before do
|
5
|
-
@example_group = Class.new(Spec::Example::ExampleGroup)
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#outline" do
|
9
|
-
it "should set the current outline to a new outline with the given name" do
|
10
|
-
@example_group.outline("name of outline")
|
11
|
-
@example_group.current_outline.should be_a(Outline)
|
12
|
-
@example_group.current_outline.name.should == "name of outline"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#fields" do
|
17
|
-
describe "when no outline has been defined" do
|
18
|
-
it "should raise an Error" do
|
19
|
-
lambda{@example_group.fields}.should raise_error(Error)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "when an outline has been defined" do
|
24
|
-
before do
|
25
|
-
@outline = Outline.new(@example_group, "name of outline")
|
26
|
-
@example_group.stubs(:current_outline).returns(@outline)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should set the fields of the last outline" do
|
30
|
-
@example_group.fields(:a, :b)
|
31
|
-
@outline.fields.should == [:a, :b]
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should symbolize the given field names" do
|
35
|
-
@example_group.fields('a', 'b')
|
36
|
-
@outline.fields.should == [:a, :b]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#values" do
|
42
|
-
describe "when there is no current outline" do
|
43
|
-
it "should raise an Error" do
|
44
|
-
lambda{@example_group.values(1, 2)}.should raise_error(Error)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "when the current outline has no fields defined" do
|
49
|
-
before do
|
50
|
-
@outline = Outline.new(@example_group, "name of outline")
|
51
|
-
@example_group.stubs(:current_outline).returns(@outline)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should raise an Error" do
|
55
|
-
lambda{@example_group.values(1, 2)}.should raise_error(Error)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "when there is a current outline with fields defined" do
|
60
|
-
before do
|
61
|
-
@outline = Outline.new(@example_group, "name of outline"){}
|
62
|
-
@outline.stubs(:fields).returns([:field_one, :field_two])
|
63
|
-
@example_group.stubs(:current_outline).returns(@outline)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should define an example based on the last outline" do
|
67
|
-
lambda{@example_group.values(1, 2)}.should change{@example_group.number_of_examples}.by(1)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should bind the given values to the example" do
|
71
|
-
@example_group.values(1, 2)
|
72
|
-
@example_group.example_proxies.last.outline_values.should == {:field_one => 1, :field_two => 2}
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should raise an ArgumentError if the number of arguments is different to the number of fields" do
|
76
|
-
lambda{@example_group.values(1)}.should raise_error(ArgumentError)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ExampleMethods do
|
4
|
-
describe "#execute" do
|
5
|
-
before do
|
6
|
-
@example_group = Class.new(Spec::Example::ExampleGroup)
|
7
|
-
@run_options = Spec::Runner::Options.new(StringIO.new, StringIO.new)
|
8
|
-
@run_options.reporter.example_group_started(@example_group)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "when outline values are present" do
|
12
|
-
before do
|
13
|
-
@proxy = Spec::Example::ExampleProxy.new("description")
|
14
|
-
@proxy.outline_values = {:x => 5}
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should give the implementation access to the outline values" do
|
18
|
-
value = nil
|
19
|
-
example_group_instance = @example_group.new(@proxy) do
|
20
|
-
value = x
|
21
|
-
end
|
22
|
-
example_group_instance.execute(@run_options, {}).should be_true
|
23
|
-
value.should == 5
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "when outline values are not present" do
|
28
|
-
before do
|
29
|
-
@proxy = Spec::Example::ExampleProxy.new("description")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should give the implementation access to the outline values" do
|
33
|
-
error = nil
|
34
|
-
example_group_instance = @example_group.new(@proxy) do
|
35
|
-
begin
|
36
|
-
x
|
37
|
-
rescue NameError => error
|
38
|
-
end
|
39
|
-
end
|
40
|
-
example_group_instance.execute(@run_options, {}).should be_true
|
41
|
-
error.should_not be_nil
|
42
|
-
error.message.should include("`x'")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
ROOT = File.dirname(File.dirname(__FILE__))
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
-
require 'rspec_outlines'
|
6
|
-
require 'spec'
|
7
|
-
require 'spec/autorun'
|
8
|
-
|
9
|
-
Spec::Runner.configure do |config|
|
10
|
-
config.mock_with :mocha
|
11
|
-
end
|
12
|
-
|
13
|
-
# So we don't have to qualify all our classes.
|
14
|
-
include RSpecOutlines
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rbconfig'
|
3
|
-
|
4
|
-
SPEC_FILE_DIRECTORY = "#{ROOT}/spec_integration/spec_files"
|
5
|
-
|
6
|
-
describe "RSpec Outlines" do
|
7
|
-
def spec
|
8
|
-
suffix = Config::CONFIG['ruby_install_name'].sub(/\Aruby/, '')
|
9
|
-
basename = "spec#{suffix}"
|
10
|
-
ENV['PATH'].split(/:/).each do |dirname|
|
11
|
-
path = File.join(dirname, basename)
|
12
|
-
return path if File.file?(path) && File.executable?(path)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def run_spec_file(path)
|
17
|
-
original_rubylib = ENV['RUBYLIB']
|
18
|
-
ENV['RUBYLIB'] = "#{ROOT}/lib"
|
19
|
-
begin
|
20
|
-
output = `#{spec} "#{path}" 2>&1`
|
21
|
-
output[/.*/]
|
22
|
-
ensure
|
23
|
-
ENV['RUBYLIB'] = original_rubylib
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
Dir["#{SPEC_FILE_DIRECTORY}/*.rb"].each do |path|
|
28
|
-
name = File.basename(path).sub(/_spec\.rb\z/, '').gsub(/_/, ' ')
|
29
|
-
expected = File.read(path).match(/\A# expect: (.*)/)[1]
|
30
|
-
it(name){run_spec_file(path).should == expected}
|
31
|
-
end
|
32
|
-
end
|
data/spec_integration/spec.opts
DELETED