generative 0.1.0 → 0.2.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb07b72eae577b93f0b1a1ad07c359febd371b2a
4
- data.tar.gz: 546a72740dba23846335a260cd990b869475e9a6
3
+ metadata.gz: 91579b9cbddd9ab1a63136fd9466b779dce20ce5
4
+ data.tar.gz: 35947c6dd629fe09df3c2d5d08ce2ad84bedfb3d
5
5
  SHA512:
6
- metadata.gz: e05ce694896ac75dbd22283c29bcf7ff6900d5928ddebbf907184944f1098c2a34c02f75d14866c0c72385a56796163307765c4cd655911379948b400e2c1d91
7
- data.tar.gz: 1af5f8fd24a3449a28c602d8be2cf33299aef47c647851f0ff3aa123252a66b3c401da015f561b7f5688cc5c9fc93734f3969337531d4320744bb9929c1cba4e
6
+ metadata.gz: 0b3e014eb4add9e5e87b633720418f1926646d4c8cd4447cc5042a0904465eb93deb19dd4b878b736920a09836cd64c97857cb2b25f71efe97e965bba78ded11
7
+ data.tar.gz: 9763f83d3d197452d419a4ad20de6a5c816fa1dc12b398c4ee07dd85e049cea097e9d4ea46b50f23de91d634ce09369cd37a60f595acd71b9bc0cab23272b80f
data/.travis.yml CHANGED
@@ -9,3 +9,5 @@ rvm:
9
9
  matrix:
10
10
  allow_failures:
11
11
  - rvm: ruby-head
12
+ script:
13
+ - rake ci
data/README.md CHANGED
@@ -26,30 +26,27 @@ end
26
26
  --require generative
27
27
  ```
28
28
 
29
- ### Modify your `Rakefile` to create separate `spec` and `generative` tasks:
29
+ ### (Optional) Require the Generative Rake task in your `Rakefile`:
30
30
 
31
31
  ```rb
32
- require 'bundler/gem_tasks'
33
32
  require 'rspec/core/rake_task'
33
+ require 'generative/rake_task'
34
34
 
35
- task default: [:spec, :generative]
36
-
37
- RSpec::Core::RakeTask.new(:spec) do |t|
38
- t.rspec_opts = '--format documentation --tag ~generative --order random'
39
- end
40
-
41
- RSpec::Core::RakeTask.new(:generative) do |t|
42
- ENV['GENERATIVE_COUNT'] = '10_000'
43
- t.rspec_opts = '--format Generative --tag generative'
44
- end
35
+ task(:default).enhance [:spec, :generative]
45
36
  ```
46
37
 
47
38
  ### Remove any random/other ordering
48
39
 
49
40
  If using RSpec 2, you'll need to make sure you remove `config.order =
50
- 'random'`, or any other ordering strategies, from your spec helper.
41
+ 'random'`, or any other ordering strategies, from your spec helper. You can
42
+ also use `Generative.running?` to only disable random ordering during
43
+ Generative runs:
44
+
45
+ ```rb
46
+ config.order = :random unless Generative.running?
47
+ ```
51
48
 
52
- In RSpec 3, this is not nessecary, because each example group (the `generative`
49
+ In RSpec 3, this is not necessary, because each example group (the `generative`
53
50
  block) can override ordering for that group.
54
51
 
55
52
  ## Usage
@@ -85,13 +82,38 @@ describe String do
85
82
  end
86
83
  ```
87
84
 
88
- Now, run your tests with `rake` or `rspec`.
85
+ ### Running
86
+
87
+ Generative comes with a `generative` command, which simply runs rspec with the
88
+ required arguments:
89
+
90
+ ```
91
+ $ generative
92
+ + GENERATIVE_COUNT=10_000
93
+ + rspec --require generative --format Generative --tag generative
94
+ Run options: include {:generative=>true}
95
+
96
+ String
97
+ #length
98
+ generative
99
+ is never negative
100
+ #reverse
101
+ generative
102
+ maintains length
103
+ is not destructive
104
+
105
+ Finished in 2.28 seconds
106
+ 30000 examples, 0 failures
107
+ ```
108
+
109
+ If you've added the Generative task to your `Rakefile`, you can also simply run
110
+ `rake ` to run all tests, including Generative ones.
89
111
 
90
112
  ### Number of Tests
91
113
 
92
114
  Generative uses the `GENERATIVE_COUNT` environment variable to control how many
93
- tests to run for each example. It defaults to 100, and in the example
94
- `Rakefile` above, we set it to 10,000.
115
+ tests to run for each example. Both the `generative` command and the example
116
+ `Rakefile` above set it to 10,000.
95
117
 
96
118
  ### Formatters
97
119
 
data/Rakefile CHANGED
@@ -1,13 +1,27 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
+ require 'generative/rake_task'
3
4
 
4
- task default: [:spec, :generative]
5
+ task default: [:spec, :generative, :acceptance]
6
+ task ci: [:spec, :generative]
5
7
 
6
- RSpec::Core::RakeTask.new(:spec) do |t|
7
- t.rspec_opts = '--format documentation --tag ~generative --order random'
8
- end
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ Generative::RakeTask.new(:generative)
10
+
11
+ desc "Verify all spec commands behave properly"
12
+ task :acceptance do
13
+ [
14
+ ['rspec', '6'],
15
+ ['rake spec', '6'],
16
+ ['rake generative', '30000'],
17
+ ['bin/generative', '30000']
18
+ ].each do |command, example_count|
19
+ result = system %{#{command} | grep "#{example_count} examples, 0 failures"}
20
+
21
+ unless result
22
+ fail "`#{command}` had an incorrect example count"
23
+ end
24
+ end
9
25
 
10
- RSpec::Core::RakeTask.new(:generative) do |t|
11
- ENV['GENERATIVE_COUNT'] ||= '10_000'
12
- t.rspec_opts = '--format Generative --tag generative'
26
+ puts "Yay!"
13
27
  end
data/bin/generative ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
4
+
5
+ require 'generative'
6
+
7
+ ENV['GENERATIVE_COUNT'] ||= '10_000'
8
+
9
+ command = %w[
10
+ rspec
11
+ --require generative
12
+ --format Generative::Formatter
13
+ --tag generative
14
+ ].join(' ')
15
+
16
+ command = "GENERATIVE_COUNT=#{ENV['GENERATIVE_COUNT']} #{command}"
17
+
18
+ puts command
19
+ system command
data/generative.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'generative'
7
- gem.version = '0.1.0'
7
+ gem.version = '0.2.0.pre1'
8
8
  gem.authors = ["Justin Campbell", "Dan McClory"]
9
9
  gem.email = ["justin@justincampbell.me", "danmcclory@gmail.com"]
10
10
  gem.description = "Generative testing for RSpec"
@@ -13,6 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.license = 'MIT'
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map { |file| File.basename file }
16
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
18
  gem.require_paths = ["lib"]
18
19
 
data/lib/generative.rb CHANGED
@@ -1,5 +1,13 @@
1
1
  require 'rspec/core'
2
2
 
3
+ module Generative
4
+ DEFAULT_COUNT = '10_000'
5
+
6
+ def self.running?
7
+ !!ENV['GENERATIVE_COUNT']
8
+ end
9
+ end
10
+
3
11
  require 'generative/dsl'
4
12
  require 'generative/formatters'
5
13
  require 'generative/ordering'
@@ -14,55 +14,57 @@ end
14
14
 
15
15
  require 'rspec/core/formatters/documentation_formatter'
16
16
 
17
- class Generative < RSpec::Core::Formatters::DocumentationFormatter
18
- def initialize(output)
19
- super(output)
20
- end
17
+ module Generative
18
+ class Formatter < RSpec::Core::Formatters::DocumentationFormatter
19
+ def initialize(output)
20
+ super(output)
21
+ end
21
22
 
22
- def example_group_started(example_group)
23
- @example_group = example_group
23
+ def example_group_started(example_group)
24
+ @example_group = example_group
24
25
 
25
- output.puts if @group_level == 0
26
+ output.puts if @group_level == 0
26
27
 
27
- if generative?(example_group)
28
- output.puts "#{current_indentation}#{detail_color('generative')}"
28
+ if generative?(example_group)
29
+ output.puts "#{current_indentation}#{detail_color('generative')}"
29
30
 
30
- @group_level += 1
31
- example_group.examples.each do |example|
32
- output.puts "#{current_indentation}#{detail_color(example.description)}"
31
+ @group_level += 1
32
+ example_group.examples.each do |example|
33
+ output.puts "#{current_indentation}#{detail_color(example.description)}"
34
+ end
35
+
36
+ @group_level -= 1
37
+ else
38
+ output.puts "#{current_indentation}#{example_group.description.strip}"
33
39
  end
34
40
 
35
- @group_level -= 1
36
- else
37
- output.puts "#{current_indentation}#{example_group.description.strip}"
41
+ @group_level += 1
38
42
  end
39
43
 
40
- @group_level += 1
41
- end
44
+ def example_passed(example)
45
+ return if generative?(example)
42
46
 
43
- def example_passed(example)
44
- return if generative?(example)
47
+ super(example)
48
+ end
45
49
 
46
- super(example)
47
- end
50
+ def example_pending(example)
51
+ return if generative?(example)
48
52
 
49
- def example_pending(example)
50
- return if generative?(example)
53
+ super(example)
54
+ end
51
55
 
52
- super(example)
53
- end
56
+ def example_failed(example)
57
+ if generative?(example)
58
+ RSpec.wants_to_quit = true
59
+ end
54
60
 
55
- def example_failed(example)
56
- if generative?(example)
57
- RSpec.wants_to_quit = true
61
+ super(example)
58
62
  end
59
63
 
60
- super(example)
61
- end
64
+ private
62
65
 
63
- private
64
-
65
- def generative?(example)
66
- example.metadata[:generative]
66
+ def generative?(example)
67
+ example.metadata[:generative]
68
+ end
67
69
  end
68
70
  end
@@ -0,0 +1,28 @@
1
+ require 'generative'
2
+ require 'rspec/core/rake_task'
3
+
4
+ module Generative
5
+ class RakeTask < RSpec::Core::RakeTask
6
+ def initialize(*args, &task_block)
7
+ setup_ivars(args)
8
+
9
+ desc "Run Generative specs" unless Rake.application.last_comment
10
+
11
+ options = %w[
12
+ --require generative
13
+ --format Generative::Formatter
14
+ --tag generative
15
+ ]
16
+
17
+ self.rspec_opts = options.join(' ')
18
+
19
+ task name, *args do |_, task_args|
20
+ RakeFileUtils.send(:verbose, verbose) do
21
+ ENV['GENERATIVE_COUNT'] ||= Generative::DEFAULT_COUNT
22
+ task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
23
+ run_task verbose
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -8,7 +8,7 @@ describe String do
8
8
  expect(string.length).to eq(3)
9
9
  end
10
10
 
11
- xit "does other stuff"
11
+ xit "still prints pending spec names"
12
12
 
13
13
  generative do
14
14
  data(:string) { "a" * rand(255) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generative
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Campbell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-18 00:00:00.000000000 Z
12
+ date: 2014-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -43,7 +43,8 @@ description: Generative testing for RSpec
43
43
  email:
44
44
  - justin@justincampbell.me
45
45
  - danmcclory@gmail.com
46
- executables: []
46
+ executables:
47
+ - generative
47
48
  extensions: []
48
49
  extra_rdoc_files: []
49
50
  files:
@@ -55,11 +56,13 @@ files:
55
56
  - LICENSE.txt
56
57
  - README.md
57
58
  - Rakefile
59
+ - bin/generative
58
60
  - generative.gemspec
59
61
  - lib/generative.rb
60
62
  - lib/generative/dsl.rb
61
63
  - lib/generative/formatters.rb
62
64
  - lib/generative/ordering.rb
65
+ - lib/generative/rake_task.rb
63
66
  - lib/generative/version.rb
64
67
  - spec/generative_spec.rb
65
68
  - spec/spec_helper.rb
@@ -78,9 +81,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
81
  version: '0'
79
82
  required_rubygems_version: !ruby/object:Gem::Requirement
80
83
  requirements:
81
- - - ">="
84
+ - - ">"
82
85
  - !ruby/object:Gem::Version
83
- version: '0'
86
+ version: 1.3.1
84
87
  requirements: []
85
88
  rubyforge_project:
86
89
  rubygems_version: 2.2.0