rspec_outlines 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/DESCRIPTION.txt ADDED
@@ -0,0 +1,12 @@
1
+ Cucumber outlines for RSpec!
2
+
3
+ describe "Adding two numbers" do
4
+ outline "should return the sum" do
5
+ (a + b).should == c
6
+ end
7
+
8
+ fields :a, :b, :c
9
+ values 1, 1, 2
10
+ values 2, 3, 5
11
+ values 1, -1, 0
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 George Ogata
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.rdoc ADDED
@@ -0,0 +1,18 @@
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/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
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
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,12 @@
1
+ module RSpecOutlines
2
+ end
3
+
4
+ require 'rspec_outlines/error'
5
+ require 'rspec_outlines/example_group'
6
+ require 'rspec_outlines/example_methods'
7
+ require 'rspec_outlines/example_proxy'
8
+ require 'rspec_outlines/outline'
9
+
10
+ Spec::Example::ExampleGroup.send :extend, RSpecOutlines::ExampleGroup
11
+ Spec::Example::ExampleGroup.send :include, RSpecOutlines::ExampleMethods
12
+ Spec::Example::ExampleProxy.send :include, RSpecOutlines::ExampleProxy
@@ -0,0 +1,3 @@
1
+ module RSpecOutlines
2
+ Error = Class.new(RuntimeError)
3
+ end
@@ -0,0 +1,28 @@
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
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,5 @@
1
+ module RSpecOutlines
2
+ module ExampleProxy
3
+ attr_accessor :outline_values
4
+ end
5
+ end
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,81 @@
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.0"
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-14}
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
@@ -0,0 +1,80 @@
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
@@ -0,0 +1,46 @@
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 ADDED
@@ -0,0 +1,2 @@
1
+ --debugger
2
+ --color
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,3 @@
1
+ --debugger
2
+ --color
3
+ --diff
@@ -0,0 +1,11 @@
1
+ # expect: .F
2
+
3
+ describe "A matcher implemented by method_missing" do
4
+ it "should work properly in the passing case" do
5
+ [].should be_empty
6
+ end
7
+
8
+ it "should work properly in the failing case" do
9
+ [1].should be_empty
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # expect: ..F
2
+
3
+ require 'rspec_outlines'
4
+
5
+ describe "Adding two numbers" do
6
+ outline "should return the sum" do
7
+ (a + b).should == c
8
+ end
9
+ fields :a, :b, :c
10
+ values 1, 1, 2
11
+ values -1, -2, -3
12
+ values 1, 2, 10
13
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_outlines
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - George Ogata
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-14 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: |
36
+ Cucumber outlines for RSpec!
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
+
49
+ email: george.ogata@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.rdoc
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - DESCRIPTION.txt
61
+ - LICENSE
62
+ - README.rdoc
63
+ - Rakefile
64
+ - VERSION
65
+ - lib/rspec_outlines.rb
66
+ - lib/rspec_outlines/error.rb
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
80
+ has_rdoc: true
81
+ homepage: http://github.com/oggy/rspec_outlines
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --charset=UTF-8
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ version:
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.3.5
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Define specs in tables.
108
+ test_files:
109
+ - spec/example_group_spec.rb
110
+ - spec/example_methods_spec.rb
111
+ - spec/spec_helper.rb