generative 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --require generative
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
6
+ matrix:
7
+ allow_failures:
8
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Justin Campbell
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,94 @@
1
+ # Generative
2
+
3
+ > Generative testing for RSpec
4
+ > [![Gem Version](https://badge.fury.io/rb/generative.png)](http://badge.fury.io/rb/generative)
5
+ > [![Build Status](https://travis-ci.org/justincampbell/generative.png?branch=master)](https://travis-ci.org/justincampbell/generative)
6
+ > [![Code Climate](https://codeclimate.com/github/justincampbell/generative.png)](https://codeclimate.com/github/justincampbell/generative)
7
+
8
+ ## Installation
9
+
10
+ You're already using RSpec 3, right? Of course you are.
11
+
12
+ ### Add Generative to your Gemfile:
13
+
14
+ ```rb
15
+ group :test do
16
+ gem 'generative'
17
+ gem 'rspec', '3.0.0.beta1'
18
+ end
19
+ ```
20
+
21
+ ### Require Generative in your `.rspec` file:
22
+
23
+ ```
24
+ --color
25
+ --format progress
26
+ --require generative
27
+ ```
28
+
29
+ ### Modify your `Rakefile` to create separate `spec` and `generative` tasks:
30
+
31
+ ```rb
32
+ require 'bundler/gem_tasks'
33
+ require 'rspec/core/rake_task'
34
+
35
+ ENV['GENERATIVE_COUNT'] = '10_000'
36
+
37
+ task default: [:spec, :generative]
38
+
39
+ RSpec::Core::RakeTask.new(:spec) do |t|
40
+ t.rspec_opts = '--format documentation --tag ~generative'
41
+ end
42
+
43
+ RSpec::Core::RakeTask.new(:generative) do |t|
44
+ t.rspec_opts = '--format Generative --tag generative'
45
+ end
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ### Specs
51
+
52
+ In your tests, add a `generative` block. This is a essentially the same as a
53
+ `context` or `describe` block. Inside the block, define some `data` as you
54
+ would a `let`. Then, write your `it`/`specify` blocks as usual (while keeping
55
+ in mind that the input could be anything).
56
+
57
+ ```rb
58
+ describe String do
59
+ let(:string) { "abc" }
60
+
61
+ describe "#reverse" do
62
+ it "reverses" do
63
+ expect(string.reverse).to eq("cba")
64
+ end
65
+
66
+ generative do
67
+ data(:string) { rand(12345).to_s }
68
+
69
+ it "maintains length" do
70
+ expect(string.reverse.length).to eq(string.length)
71
+ end
72
+
73
+ it "is not destructive" do
74
+ expect(string.reverse.reverse).to eq(string)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ ```
80
+
81
+ Now, run your tests with `rake` or `rspec`.
82
+
83
+ ### Number of Tests
84
+
85
+ Generative uses the `GENERATIVE_COUNT` environment variable to control how many
86
+ tests to run for each example. It defaults to 100, and in the example
87
+ `Rakefile` above, we set it to 10,000.
88
+
89
+ ### Formatters
90
+
91
+ Given the examples above, running `rspec` will use the default "progress"
92
+ formatter. Requiring generative will modify this formatter to output blue dots
93
+ instead of green for generative tests. Generative also includes it's own
94
+ formatter, which will only display generative test names once, also in blue.
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ ENV['GENERATIVE_COUNT'] = '10_000'
5
+
6
+ task default: [:spec, :generative]
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.rspec_opts = '--format documentation --tag ~generative'
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new(:generative) do |t|
13
+ t.rspec_opts = '--format Generative --tag generative'
14
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'generative'
7
+ gem.version = '0.0.1'
8
+ gem.authors = ["Justin Campbell"]
9
+ gem.email = ["justin@justincampbell.me"]
10
+ gem.description = "Generative testing for RSpec"
11
+ gem.summary = "Generative testing for RSpec"
12
+ gem.homepage = "https://github.com/justincampbell/generative"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.require_paths = ["lib"]
17
+
18
+ gem.add_dependency 'rspec', '3.0.0.beta1'
19
+
20
+ gem.add_development_dependency 'rake'
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec/core'
2
+
3
+ require 'generative/dsl'
4
+ require 'generative/formatters'
5
+ require 'generative/ordering'
@@ -0,0 +1,12 @@
1
+ class RSpec::Core::ExampleGroup
2
+ def self.generative(name = nil, &block)
3
+ name = "(#{name})" if name
4
+ name = "\033[36mgenerative#{name}\033[0m"
5
+
6
+ describe(name, generative: true, order: :generative, &block)
7
+ end
8
+
9
+ class << self
10
+ alias_method :data, :let
11
+ end
12
+ end
@@ -0,0 +1,69 @@
1
+ require 'rspec/core/formatters/progress_formatter'
2
+
3
+ class RSpec::Core::Formatters::ProgressFormatter
4
+ def example_passed(example)
5
+ super(example)
6
+
7
+ if example.metadata[:generative]
8
+ output.print detail_color('.')
9
+ else
10
+ output.print success_color('.')
11
+ end
12
+ end
13
+ end
14
+
15
+ require 'rspec/core/formatters/documentation_formatter'
16
+
17
+ class Generative < RSpec::Core::Formatters::DocumentationFormatter
18
+ def initialize(output)
19
+ super(output)
20
+ end
21
+
22
+ def example_group_started(example_group)
23
+ @example_group = example_group
24
+
25
+ output.puts if @group_level == 0
26
+
27
+ if generative?(example_group)
28
+ output.puts "#{current_indentation}#{detail_color('generative')}"
29
+
30
+ @group_level += 1
31
+ example_group.examples.each do |example|
32
+ output.puts "#{current_indentation}#{detail_color(example.description)}"
33
+ end
34
+
35
+ @group_level -= 1
36
+ else
37
+ output.puts "#{current_indentation}#{example_group.description.strip}"
38
+ end
39
+
40
+ @group_level += 1
41
+ end
42
+
43
+ def example_passed(example)
44
+ return if generative?(example)
45
+
46
+ super(example)
47
+ end
48
+
49
+ def example_pending(example)
50
+ return if generative?(example)
51
+
52
+ super(example)
53
+ end
54
+
55
+ def example_failed(example)
56
+ if generative?(example)
57
+ RSpec.wants_to_quit = true
58
+ return
59
+ end
60
+
61
+ super(example)
62
+ end
63
+
64
+ private
65
+
66
+ def generative?(example)
67
+ example.metadata[:generative]
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.configure do |rspec|
2
+ rspec.register_ordering :generative do |examples|
3
+ number_of_examples = ENV.fetch('GENERATIVE_COUNT', '100').to_i
4
+
5
+ examples * number_of_examples
6
+ end
7
+ end
File without changes
@@ -0,0 +1,39 @@
1
+ require 'generative'
2
+
3
+ describe String do
4
+ let(:string) { "abc" }
5
+
6
+ describe "#length" do
7
+ it "counts characters" do
8
+ expect(string.length).to eq(3)
9
+ end
10
+
11
+ xit "does other stuff"
12
+
13
+ generative do
14
+ data(:string) { "a" * rand(255) }
15
+
16
+ it "is never negative", :generative do
17
+ expect(string.length).to be >= 0
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#reverse" do
23
+ it "reverses" do
24
+ expect(string.reverse).to eq("cba")
25
+ end
26
+
27
+ generative do
28
+ data(:string) { rand(12345).to_s }
29
+
30
+ it "maintains length" do
31
+ expect(string.reverse.length).to eq(string.length)
32
+ end
33
+
34
+ it "is not destructive" do
35
+ expect(string.reverse.reverse).to eq(string)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ # Limit the spec run to only specs with the focus metadata. If no specs have
9
+ # the filtering metadata and `run_all_when_everything_filtered = true` then
10
+ # all specs will run.
11
+ #config.filter_run :focus
12
+
13
+ # Run all specs when none match the provided filter. This works well in
14
+ # conjunction with `config.filter_run :focus`, as it will run the entire
15
+ # suite when no specs have `:filter` metadata.
16
+ #config.run_all_when_everything_filtered = true
17
+
18
+ # Run specs in random order to surface order dependencies. If you find an
19
+ # order dependency and want to debug it, you can fix the order by providing
20
+ # the seed, which is printed after each run.
21
+ # --seed 1234
22
+ #config.order = 'random'
23
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: generative
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin Campbell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0.beta1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0.beta1
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Generative testing for RSpec
47
+ email:
48
+ - justin@justincampbell.me
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - .travis.yml
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - generative.gemspec
61
+ - lib/generative.rb
62
+ - lib/generative/dsl.rb
63
+ - lib/generative/formatters.rb
64
+ - lib/generative/ordering.rb
65
+ - lib/generative/version.rb
66
+ - spec/generative_spec.rb
67
+ - spec/spec_helper.rb
68
+ homepage: https://github.com/justincampbell/generative
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.23
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Generative testing for RSpec
92
+ test_files:
93
+ - spec/generative_spec.rb
94
+ - spec/spec_helper.rb