genspec 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3740bec750e728d9bb6506135c75d721b407214a
4
+ data.tar.gz: 0e822cbddfcf0ca68e68a44bfb6dd868fa661c0b
5
+ SHA512:
6
+ metadata.gz: b2f5e61ad14a6af712f092a67721ca0a7312e01c472c1c78a8abb2730d3babeab14dd4ea381d1272299b46445e0dd475e607f546d9867086dc54a02ecec08715
7
+ data.tar.gz: 51076fb0b0f07ad9ce83544a88e7e21d8be623a1d2ac14c4a39950e3b203193104b82e94dcb30cd3ed77ca5f868f03d58a6716a4e0e238476a65e942bf8c5b9a
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  .idea
2
+ .rvmrc
2
3
 
3
4
  ## MAC OS
4
5
  .DS_Store
@@ -21,3 +22,5 @@ rdoc
21
22
  pkg
22
23
 
23
24
  ## PROJECT::SPECIFIC
25
+ Gemfile.lock
26
+ coverage
@@ -1,16 +1,34 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.2
4
- - 1.9.3
2
+ - 2.0.0
3
+ - 2.1.8
4
+ - 2.2.4
5
+ - 2.3.0
5
6
  - ruby-head
6
- - ree
7
- - jruby-18mode
8
- - jruby-19mode
9
- - jruby-head
10
- - rbx-18mode
11
7
  - rbx-19mode
12
8
 
13
9
  env:
14
- - RAILS_VERSION="~> 3.1"
15
- - RAILS_VERSION="~> 3.2"
16
- - RAILS_VERSIOn="4.0.0.beta1"
10
+ - RAILS_VERSION="~> 3.1.0"
11
+ - RAILS_VERSION="~> 3.2.0"
12
+ - RAILS_VERSION="~> 4.0.0"
13
+ - RAILS_VERSION="~> 4.1.0"
14
+ - RAILS_VERSION="~> 4.2.0"
15
+ - RAILS_VERSION="~> 5.0.0"
16
+ # Do we need to test each rspec version with each rails?
17
+ # Since rspec has no direct relation to rails (except through rspec-rails,
18
+ # which isn't considered here), I'm assuming no.
19
+ - RAILS_VERSION="none" RSPEC_VERSION="~> 2.0"
20
+ - RAILS_VERSION="none" RSPEC_VERSION="~> 3.0"
21
+
22
+ matrix:
23
+ allow_failures:
24
+ - rvm: ruby-head
25
+ - rvm: rbx-19mode
26
+ exclude:
27
+ - rvm: 2.3.0
28
+ env: RAILS_VERSION="~> 3.1.0"
29
+ - rvm: 2.3.0
30
+ env: RAILS_VERSION="~> 3.2.0"
31
+ - rvm: 2.0.0
32
+ env: RAILS_VERSION="~> 5.0.0"
33
+ - rvm: 2.1.8
34
+ env: RAILS_VERSION="~> 5.0.0"
data/Gemfile CHANGED
@@ -2,4 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', ENV['RAILS_VERSION'] || '>= 3'
5
+ if ENV['RAILS_VERSION'] != 'none'
6
+ gem 'rails', ENV['RAILS_VERSION'] || '>= 3'
7
+ end
@@ -1,4 +1,4 @@
1
- = GenSpec
1
+ = GenSpec {<img src="https://travis-ci.org/sinisterchipmunk/genspec.png?branch=master" alt="Build Status" />}[https://travis-ci.org/sinisterchipmunk/genspec] {<img src="https://codeclimate.com/github/sinisterchipmunk/genspec.png" />}[https://codeclimate.com/github/sinisterchipmunk/genspec] {<img src="https://coveralls.io/repos/sinisterchipmunk/genspec/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/sinisterchipmunk/genspec]
2
2
 
3
3
  Simple, expressive generator testing for RSpec. This version of GenSpec supports testing either Thor generators (in standalone applications/gems) or Rails 3 generators for Rails apps.
4
4
 
@@ -28,47 +28,55 @@ A basic generator spec might look something like this:
28
28
  describe :custom_controller do
29
29
  context "with no arguments or options" do
30
30
  it "should generate a help message" do
31
- subject.should output("A Help Message")
31
+ expect(subject).to output("A Help Message")
32
32
  end
33
33
  end
34
34
 
35
35
  with_args :users do
36
36
  it "should generate a UsersController" do
37
- subject.should generate("app/controllers/users_controller.rb") { |content|
38
- content.should =~ /class UserController/
37
+ expect(subject).to generate("app/controllers/users_controller.rb") { |content|
38
+ expect(content).to =~ /class UserController/
39
39
  }
40
40
  end
41
41
  end
42
42
  end
43
+
44
+ === Checking an engine
45
+
46
+ You may need to specify a base class, particularly if you are testing a Rails engine:
47
+
48
+ describe "base_class:custom_controller" do
49
+ ...
50
+ end
43
51
 
44
52
  === Checking Generated Files
45
53
 
46
54
  This is the preferred way to test files that were generated, because this matcher checks your generator's *behavior*. The test won't care _how_ a file is generated, as long as it _is_ generated. It's as simple as passing the name of the file you expected to be generated:
47
55
 
48
56
  it "should generate a readme file" do
49
- subject.should generate("README")
57
+ expect(subject).to generate("README")
50
58
  end
51
59
 
52
60
  You can also check the generated file's content by simply passing a block. The _content_ argument in the block is
53
61
  a simple String containing the content of the file:
54
62
 
55
63
  it "should generate a model called 'user'" do
56
- subject.should generate("app/models/user.rb") { |content|
57
- content.should =~ /class User < ActiveRecord\:\:Base/
64
+ expect(subject).to generate("app/models/user.rb") { |content|
65
+ expect(content).to =~ /class User < ActiveRecord\:\:Base/
58
66
  }
59
67
  end
60
68
 
61
69
  You can also very simply ensure that the generator runs without error, without any further validation, by omitting all arguments:
62
70
 
63
71
  it "should generate successfully" do
64
- subject.should generate
72
+ expect(subject).to generate
65
73
  end
66
74
 
67
75
  Finally, you could pass a block but no other arguments to +generate+ in order to check the generator's results the old-fashioned way:
68
76
 
69
77
  it "should generate a model called 'user'" do
70
- subject.should generate {
71
- File.read("app/models/user.rb").should =~ /class User < ActiveRecord\:\:Base/
78
+ expect(subject).to generate {
79
+ expect(File.read("app/models/user.rb")).to =~ /class User < ActiveRecord\:\:Base/
72
80
  }
73
81
  end
74
82
 
@@ -81,17 +89,17 @@ However, sometimes you need to verify that some action occurs which can't be val
81
89
  All 3 of the following examples perform exactly the same test. Use whichever seems the most expressive to you. (I prefer the first one.)
82
90
 
83
91
  it "should add a gem source" do
84
- subject.should add_source("http://gems.github.com")
92
+ expect(subject).to add_source("http://gems.github.com")
85
93
  end
86
94
 
87
95
  # -or-
88
96
  it "should add a gem source" do
89
- subject.should call_action(:add_source, "http://gems.github.com")
97
+ expect(subject).to call_action(:add_source, "http://gems.github.com")
90
98
  end
91
99
 
92
100
  # -or-
93
101
  it "should add a gem source" do
94
- subject.should generate(:add_source, "http://gems.github.com")
102
+ expect(subject).to generate(:add_source, "http://gems.github.com")
95
103
  end
96
104
 
97
105
  You can stop passing arguments at any time. This has the effect of widening the range of acceptable parameters. For
@@ -99,13 +107,13 @@ instance, the following example does the same thing but will accept _any_ source
99
107
  action is called:
100
108
 
101
109
  it "should add a gem source" do
102
- subject.should generate(:add_source)
110
+ expect(subject).to generate(:add_source)
103
111
  end
104
112
 
105
113
  Similarly, you can get away with specifying only the some of a sequence of arguments; the omitted arguments will accept any value, while the specified ones will be tested. Another example:
106
114
 
107
115
  it "should inject into file" do
108
- subject.should inject_into_file("config/environment.rb", "config.gem :thor")
116
+ expect(subject).to inject_into_file("config/environment.rb", "config.gem :thor")
109
117
  end
110
118
 
111
119
  # if the generator includes the following action, the test will
@@ -125,12 +133,12 @@ If you need to test the generator's feedback rather than the generator's results
125
133
 
126
134
  # Example 1: String
127
135
  it "should generate a help message" do
128
- subject.should output("A Help Message")
136
+ expect(subject).to output("A Help Message")
129
137
  end
130
138
 
131
139
  # Example 2: Regular Expression
132
140
  it "should generate a help message" do
133
- subject.should output(/A [hH]elp Message/)
141
+ expect(subject).to output(/A [hH]elp Message/)
134
142
  end
135
143
 
136
144
 
@@ -209,10 +217,10 @@ Here's an example that verifies that a file is created by the generator, but tha
209
217
 
210
218
  describe :controller do
211
219
  with_args "welcome" do
212
- it { should generate("app/controllers/welcome_controller.rb") }
220
+ it { is_expected.to generate("app/controllers/welcome_controller.rb") }
213
221
 
214
222
  with_options :behavior => :revoke do
215
- it { should delete("app/controllers/welcome_controller.rb") }
223
+ it { is_expected.to delete("app/controllers/welcome_controller.rb") }
216
224
  end
217
225
  end
218
226
  end
@@ -239,8 +247,8 @@ You can even nest such structures within various contexts:
239
247
  within_source_root { touch "config/routes.rb" }
240
248
 
241
249
  it "should insert the new route" do
242
- subject.should generate {
243
- File.read("config/routes.rb").should_not be_blank
250
+ expect(subject).to generate {
251
+ expect(File.read("config/routes.rb")).not_to be_blank
244
252
  }
245
253
  end
246
254
  end
data/Rakefile CHANGED
@@ -5,10 +5,12 @@ def run(*args)
5
5
  raise "tests failed" unless system *args
6
6
  end
7
7
 
8
+ require 'coveralls/rake/task'
9
+ Coveralls::RakeTask.new
10
+
8
11
  task :default do
9
12
  run "rspec", "spec"
10
- ENV['USE_RAILS'] = '1'
11
- run "rspec", "spec"
13
+ Rake::Task['coveralls:push'].invoke
12
14
  end
13
15
 
14
16
  begin
@@ -8,22 +8,28 @@ Gem::Specification.new do |s|
8
8
 
9
9
  s.authors = ["Colin MacKenzie IV"]
10
10
  s.date = '2010-07-08'
11
- s.description = %q{Simple, expressive Thor and/or Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.}
11
+ s.description = %q{Simple, expressive Thor and/or Rails 3+ generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.}
12
12
  s.email = 'sinisterchipmunk@gmail.com'
13
13
  s.extra_rdoc_files = [
14
14
  "LICENSE",
15
15
  "README.rdoc"
16
16
  ]
17
17
  s.files = `git ls-files`.split(/\n/)
18
- s.homepage = %q{http://www.thoughtsincomputation.com}
18
+ s.homepage = %q{http://github.com/sinisterchipmunk/genspec}
19
19
  s.rdoc_options = ["--charset=UTF-8"]
20
20
  s.require_paths = ["lib"]
21
21
  s.rubygems_version = %q{1.3.7}
22
- s.summary = %q{Simple, expressive Thor and/or Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.}
22
+ s.summary = %q{Simple, expressive Thor and/or Rails 3+ generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.}
23
23
  s.test_files = Dir["spec/**/*"]
24
24
 
25
25
  s.add_dependency 'thor'
26
- s.add_dependency 'rspec', '~> 2'
27
- s.add_dependency 'sc-core-ext', "~> 1.2.1"
26
+ if ENV['RSPEC_VERSION']
27
+ s.add_dependency 'rspec', ENV['RSPEC_VERSION']
28
+ else
29
+ s.add_dependency 'rspec', '>= 2', '< 4'
30
+ end
31
+
32
+ s.add_development_dependency 'coveralls'
33
+ s.add_development_dependency 'rake'
28
34
  end
29
35
 
@@ -2,7 +2,7 @@ require 'thor'
2
2
  if defined?(Rails)
3
3
  if Rails::VERSION::MAJOR == 2
4
4
  raise "Use genspec 0.1.x for Rails 2; this version is for Rails 3."
5
- elsif [3, 4].include? Rails::VERSION::MAJOR
5
+ elsif [3, 4, 5].include? Rails::VERSION::MAJOR
6
6
  require 'rails/generators'
7
7
  else
8
8
  raise "Unsupported Rails version: #{Rails::VERSION::STRING}"
@@ -11,8 +11,9 @@ end
11
11
 
12
12
  begin
13
13
  require 'rspec/core'
14
+ require 'rspec/version'
14
15
  rescue LoadError
15
- raise "GenSpec requires RSpec v2.0."
16
+ raise "GenSpec requires RSpec v2.0 or newer."
16
17
  end
17
18
 
18
19
  require 'fileutils'
@@ -20,8 +21,7 @@ require 'fileutils'
20
21
  module GenSpec
21
22
  def self.root; @root; end
22
23
  def self.root=(root); @root = root; end
23
-
24
- require 'sc-core-ext'
24
+
25
25
  require 'genspec/version' unless defined?(GenSpec::VERSION)
26
26
  require 'genspec/shell'
27
27
  require 'genspec/matchers'
@@ -29,7 +29,13 @@ module GenSpec
29
29
  end
30
30
 
31
31
  RSpec.configure do |config|
32
- config.include GenSpec::GeneratorExampleGroup, :example_group => { :file_path => /spec[\/]generators/ }
32
+ if RSpec::Version::STRING[0] == '2'
33
+ config.include GenSpec::GeneratorExampleGroup, example_group: { file_path: /spec[\/]generators/ }
34
+ elsif RSpec::Version::STRING[0] == '3'
35
+ config.include GenSpec::GeneratorExampleGroup, file_path: /spec[\/]generators/
36
+ else
37
+ raise "unexpected rspec version: #{RSpec::Version::STRING}"
38
+ end
33
39
 
34
40
  # Kick off the action wrappers.
35
41
  #
@@ -58,7 +58,7 @@ module GenSpec
58
58
  # end
59
59
  #
60
60
  def with_args(*args, &block)
61
- options = args.extract_options!
61
+ options = args.last.kind_of?(Hash) ? args.pop : {}
62
62
  args = args.flatten.collect { |c| c.to_s } unless options[:object]
63
63
 
64
64
  if block_given?
@@ -217,7 +217,7 @@ module GenSpec
217
217
  if genspec_subclass?
218
218
  superclass.generator
219
219
  else
220
- describes || description
220
+ described_class || description
221
221
  end
222
222
  end
223
223
 
@@ -9,15 +9,15 @@ module GenSpec
9
9
  # :migration_template, :route_resources
10
10
  #
11
11
  # Examples:
12
- # subject.should generate(:file, ...)
13
- # subject.should generate("vendor/plugins/will_paginate/init.rb")
12
+ # expect(subject).to generate(:file, ...)
13
+ # expect(subject).to generate("vendor/plugins/will_paginate/init.rb")
14
14
  #
15
15
  def generate(kind = nil, *args, &block)
16
16
  if kind.kind_of?(Symbol)
17
- # subject.should generate(:file, ...)
17
+ # expect(subject).to generate(:file, ...)
18
18
  call_action(kind, *args, &block)
19
19
  else
20
- # subject.should generate("vendor/plugins/will_paginate/init.rb")
20
+ # expect(subject).to generate("vendor/plugins/will_paginate/init.rb")
21
21
  GenSpec::Matchers::ResultMatcher.new(kind, &block)
22
22
  end
23
23
  end
@@ -27,7 +27,7 @@ module GenSpec
27
27
  # completes its run.
28
28
  #
29
29
  # Example:
30
- # subject.should delete("path/to/file")
30
+ # expect(subject).to delete("path/to/file")
31
31
  #
32
32
  def delete(filename)
33
33
  within_source_root do
@@ -35,11 +35,11 @@ module GenSpec
35
35
  FileUtils.touch filename
36
36
  end
37
37
 
38
- generate { File.should_not exist(filename) }
38
+ generate { expect(File).not_to exist(filename) }
39
39
  end
40
40
 
41
41
  # ex:
42
- # subject.should call_action(:create_file, ...)
42
+ # expect(subject).to call_action(:create_file, ...)
43
43
  #
44
44
  def call_action(kind, *args, &block)
45
45
  GenSpec::Matchers::GenerationMethodMatcher.for_method(kind, *args, &block)
@@ -56,18 +56,21 @@ module GenSpec
56
56
  instance_methods = base.instance_methods.collect { |m| m.to_s }
57
57
 
58
58
  # ex:
59
- # subject.should create_file(...)
59
+ # expect(subject).to create_file(...)
60
60
  # equivalent to:
61
- # subject.should call_action(:create_file, ...)
61
+ # expect(subject).to call_action(:create_file, ...)
62
62
 
63
63
  GenSpec::Matchers::GenerationMethodMatcher.generation_methods.each do |method_name|
64
64
  # don't overwrite existing methods. since the user expects this to fire FIRST,
65
65
  # it's as if this method's been "overridden". See #included and #extended.
66
66
  next if instance_methods.include?(method_name.to_s)
67
67
  base.class_eval <<-end_code
68
- def #{method_name}(*args, &block) # def create_file(*args, &block)
69
- call_action(#{method_name.inspect}, *args, &block) # call_action('create_file', *args, &block)
70
- end # end
68
+ # def create_file(*args, &block)
69
+ # call_action('create_file', *args, &block)
70
+ # end
71
+ def #{method_name}(*args, &block)
72
+ call_action(#{method_name.inspect}, *args, &block)
73
+ end
71
74
  end_code
72
75
  end
73
76
  end
@@ -19,7 +19,9 @@ module GenSpec
19
19
  end
20
20
 
21
21
  def matches?(generator)
22
- @described = generator[:described]
22
+ @described = generator[:described].to_s
23
+ base = nil
24
+ base, @described = @described.split(/:/) if @described =~ /:/
23
25
  @args = generator[:args]
24
26
  @generator_options = generator[:generator_options]
25
27
  @shell = GenSpec::Shell.new(generator[:output] || "", generator[:input] || "")
@@ -29,7 +31,7 @@ module GenSpec
29
31
  @generator = @described
30
32
  else
31
33
  if defined?(Rails)
32
- @generator = Rails::Generators.find_by_namespace(@described)
34
+ @generator = Rails::Generators.find_by_namespace(@described, base)
33
35
  else
34
36
  @generator = Thor::Util.find_by_namespace(@described)
35
37
  end
@@ -113,15 +115,25 @@ module GenSpec
113
115
  end
114
116
 
115
117
  @destination_root = tempdir
116
- @generator.start @args || [], @generator_options.reverse_merge(
117
- :shell => @shell,
118
- :destination_root => destination_root
119
- )
118
+ defaults = { :shell => @shell, :destination_root => destination_root }
119
+ with_captured_io do
120
+ @generator.start @args || [], defaults.merge(@generator_options)
121
+ end
120
122
  check_for_errors
121
123
  generated
122
124
  end
123
125
  end
124
126
  end
127
+
128
+ def with_captured_io
129
+ stdout, stderr, stdin = $stdout, $stderr, $stdin
130
+ begin
131
+ $stdout, $stderr, $stdin = @shell.output, @shell.output, @shell.input
132
+ yield
133
+ ensure
134
+ $stdout, $stderr, $stdin = stdout, stderr, stdin
135
+ end
136
+ end
125
137
 
126
138
  def inject_error_handlers!
127
139
  interceptor = self
@@ -32,8 +32,8 @@ class GenSpec::Matchers::GenerationMethodMatcher < GenSpec::Matchers::Base
32
32
  def report_actual_args(args)
33
33
  # save a reference to the set of args that most *closely* matched the expectation.
34
34
  return(@actual_args = args) if @actual_args.nil?
35
- matches = (method_args % args).length
36
- if matches > (method_args % @actual_args).length
35
+ matches = (method_args & args).length
36
+ if matches > (method_args & @actual_args).length
37
37
  @actual_args = args
38
38
  end
39
39
  end
@@ -42,7 +42,7 @@ class GenSpec::Matchers::GenerationMethodMatcher < GenSpec::Matchers::Base
42
42
  "expected to generate a call to #{method_name.inspect}#{with_args} but #{what}"
43
43
  end
44
44
 
45
- def negative_failure_message
45
+ def failure_message_when_negated
46
46
  "expected not to generate a call to #{method_name.inspect}#{with_args} but it happened anyway"
47
47
  end
48
48
 
@@ -85,8 +85,9 @@ class GenSpec::Matchers::GenerationMethodMatcher < GenSpec::Matchers::Base
85
85
 
86
86
  send(:"#{method_name}_without_intercept", *argus, &block)
87
87
  end
88
-
89
- alias_method_chain :"#{method_name}", :intercept
88
+
89
+ alias_method :"#{method_name}_without_intercept", :"#{method_name}"
90
+ alias_method :"#{method_name}", :"#{method_name}_with_intercept"
90
91
  end
91
92
  end
92
93
  end
@@ -109,7 +110,7 @@ class GenSpec::Matchers::GenerationMethodMatcher < GenSpec::Matchers::Base
109
110
  # GENERATION_CLASSES. This is the list of methods that will be converted
110
111
  # into matchers, which can be used like so:
111
112
  #
112
- # subject.should create_file(. . .)
113
+ # expect(subject).to create_file(. . .)
113
114
  #
114
115
  # See also GENERATION_CLASSES
115
116
  #
@@ -117,7 +118,9 @@ class GenSpec::Matchers::GenerationMethodMatcher < GenSpec::Matchers::Base
117
118
  GENERATION_CLASSES.inject([]) do |arr, mod|
118
119
  if mod.kind_of?(String)
119
120
  next arr if !defined?(Rails) && mod =~ /^Rails/
120
- mod = mod.constantize
121
+ mod = mod.split('::').inject(Kernel) do |container, name|
122
+ container.const_get(name)
123
+ end
121
124
  end
122
125
  arr.concat mod.public_instance_methods.collect { |i| i.to_s }.reject { |i| i =~ /=/ }
123
126
  arr
@@ -127,10 +130,10 @@ class GenSpec::Matchers::GenerationMethodMatcher < GenSpec::Matchers::Base
127
130
  # called from GenSpec::Matchers#call_action
128
131
  #
129
132
  # example:
130
- # subject.should call_action(:create_file, ...)
133
+ # expect(subject).to call_action(:create_file, ...)
131
134
  #
132
135
  # equivalent to:
133
- # subject.should GenSpec::Matchers::GenerationMethodMatcher.for_method(:create_file, ...)
136
+ # expect(subject).to GenSpec::Matchers::GenerationMethodMatcher.for_method(:create_file, ...)
134
137
  #
135
138
  def for_method(which, *args, &block)
136
139
  if generation_methods.include?(which.to_s)
@@ -25,7 +25,7 @@ module GenSpec
25
25
  "expected to match #{@regexp.inspect}, but did not"
26
26
  end
27
27
 
28
- def negative_failure_message
28
+ def failure_message_when_negated
29
29
  output + "\n" \
30
30
  "expected not to match #{@regexp.inspect}, but did"
31
31
  end
@@ -30,7 +30,7 @@ module GenSpec
30
30
  "Expected to generate #{filename}"
31
31
  end
32
32
 
33
- def negative_failure_message
33
+ def failure_message_when_negated
34
34
  "Expected to not generate #{filename}"
35
35
  end
36
36
  end
@@ -10,14 +10,6 @@ module GenSpec
10
10
  alias_method :output, :stdout
11
11
  alias_method :output=, :stdout=
12
12
 
13
- Thor::Shell::SHELL_DELEGATED_METHODS.each do |method|
14
- eval <<-end_code
15
- def #{method}(*args, &block) # def yes?(*args, &block)
16
- push_std { super(*args, &block) } # push_std { super(*args, &block) }
17
- end # end
18
- end_code
19
- end
20
-
21
13
  def ask(statement, color = nil)
22
14
  say "#{statement} ", color
23
15
  response = stdin.gets
@@ -42,13 +34,6 @@ module GenSpec
42
34
  end
43
35
 
44
36
  private
45
- def push_std
46
- _stderr, _stdout, _stdin = $stderr, $stdout, $stdin
47
- $stderr, $stdout, $stdin = stderr, stdout, stdin
48
- yield
49
- ensure
50
- $stderr, $stdout, $stdin = _stderr, _stdout, _stdin
51
- end
52
37
 
53
38
  def init_stream(which, value)
54
39
  if value.kind_of?(String)
@@ -1,8 +1,8 @@
1
1
  module GenSpec
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 2
5
- PATCH = 8
4
+ MINOR = 3
5
+ PATCH = 0
6
6
  RELEASE = nil
7
7
 
8
8
  STRING = (RELEASE ? [MAJOR, MINOR, PATCH, RELEASE] : [MAJOR, MINOR, PATCH]).join('.')
@@ -4,7 +4,8 @@ if defined?(Rails)
4
4
  describe :my_migration do
5
5
  it "should run migration template" do
6
6
  # bug, raising NameError: undefined local variable or method `interceptor'
7
- proc { subject.should generate(:migration_template, "1", "2") }.should_not raise_error(NameError)
7
+ expect(proc { expect(subject).to generate(:migration_template, "1", "2")
8
+ }).not_to raise_error
8
9
  end
9
10
  end
10
11
  end
@@ -3,29 +3,31 @@ require 'spec_helper'
3
3
  describe :question do
4
4
  context "without input" do
5
5
  it "should raise an error" do
6
- proc { subject.should output("Are you a GOD?") }.should raise_error
6
+ expect(proc { expect(subject).to output("Are you a GOD?")
7
+ }).to raise_error
7
8
  end
8
9
  end
9
10
 
10
11
  with_input "yes" do
11
12
  it "should act upon something" do
12
- subject.should act_upon("something")
13
- subject.should output(/Acted upon something/)
13
+ expect(subject).to act_upon("something")
14
+ expect(subject).to output(/Acted upon something/)
14
15
  end
15
16
 
16
17
  it "should not raise an error" do
17
- proc { subject.should output("Good.") }.should_not raise_error
18
+ expect(proc { expect(subject).to output("Good.") }).not_to raise_error
18
19
  end
19
20
  end
20
21
 
21
22
  with_input "no" do
22
23
  it "should act upon something" do
23
- subject.should act_upon("something")
24
- subject.should output(/Acted upon something/)
24
+ expect(subject).to act_upon("something")
25
+ expect(subject).to output(/Acted upon something/)
25
26
  end
26
27
 
27
28
  it "should not raise an error" do
28
- proc { subject.should output("You're new around here, aren't you?") }.should_not raise_error
29
+ expect(proc { expect(subject).to output("You're new around here, aren't you?")
30
+ }).not_to raise_error
29
31
  end
30
32
  end
31
33
  end
@@ -7,49 +7,49 @@ describe :test_rails3 do
7
7
 
8
8
  it "should modify Gemfile" do
9
9
  out = ""
10
- subject.should generate {
11
- File.read("Gemfile").strip.should_not be_blank
10
+ expect(subject).to generate {
11
+ expect(File.read("Gemfile").strip).not_to be_empty
12
12
  out.concat File.read("Gemfile")
13
13
  }
14
- out.strip.should == 'source "http://gems.github.com/"'
14
+ expect(out.strip).to match %r(\Asource ['"]http://gems.github.com/['"]\z)
15
15
  end
16
16
 
17
17
  context "with no options or arguments" do
18
18
  it "should generate a file called default_file" do
19
- subject.should generate("default_file")
20
- subject.should_not generate("some_other_file")
19
+ expect(subject).to generate("default_file")
20
+ expect(subject).not_to generate("some_other_file")
21
21
 
22
- subject.should call_action(:create_file)
23
- subject.should call_action(:create_file, "default_file")
24
- subject.should_not call_action(:create_file, "some_other_file")
22
+ expect(subject).to call_action(:create_file)
23
+ expect(subject).to call_action(:create_file, "default_file")
24
+ expect(subject).not_to call_action(:create_file, "some_other_file")
25
25
 
26
- subject.should create_file
27
- subject.should create_file('default_file')
28
- subject.should_not create_file("some_other_file")
26
+ expect(subject).to create_file
27
+ expect(subject).to create_file('default_file')
28
+ expect(subject).not_to create_file("some_other_file")
29
29
  end
30
30
 
31
31
  it "should generate a file with specific content" do
32
- subject.should generate("default_file") { |content| content.should == "content!" }
33
- subject.should generate("default_file") { |content| content.should_not == "!content" }
34
- subject.should_not generate("some_other_file")
32
+ expect(subject).to generate("default_file") { |content| expect(content).to eq "content!" }
33
+ expect(subject).to generate("default_file") { |content| expect(content).not_to eq "!content" }
34
+ expect(subject).not_to generate("some_other_file")
35
35
  end
36
36
 
37
37
  it "should generate a template called 'default_template'" do
38
- subject.should generate(:template)
39
- subject.should generate(:template, 'file', 'file_template')
38
+ expect(subject).to generate(:template)
39
+ expect(subject).to generate(:template, 'file', 'file_template')
40
40
  end
41
41
 
42
42
  it "should output 'create file'" do
43
- subject.should output(/create\s+default_file/)
43
+ expect(subject).to output(/create\s+default_file/)
44
44
  end
45
45
 
46
46
  it "shoud generate a directory called 'a_directory'" do
47
- subject.should generate(:empty_directory)
48
- subject.should generate(:empty_directory, "a_directory")
49
- subject.should generate("a_directory")
50
- subject.should_not generate(:empty_directory, 'another_directory')
51
- subject.should empty_directory("a_directory")
52
- subject.should_not empty_directory("another_directory")
47
+ expect(subject).to generate(:empty_directory)
48
+ expect(subject).to generate(:empty_directory, "a_directory")
49
+ expect(subject).to generate("a_directory")
50
+ expect(subject).not_to generate(:empty_directory, 'another_directory')
51
+ expect(subject).to empty_directory("a_directory")
52
+ expect(subject).not_to empty_directory("another_directory")
53
53
  end
54
54
 
55
55
  # if the other tests pass then it seems to be working properly, but let's make sure
@@ -57,18 +57,18 @@ describe :test_rails3 do
57
57
  # will work fine too.
58
58
  it 'should add_source "http://gems.github.com/"' do
59
59
  if defined?(Rails)
60
- subject.should add_source("http://gems.github.com/")
60
+ expect(subject).to add_source("http://gems.github.com/")
61
61
  end
62
62
  end
63
63
  end
64
64
 
65
65
  with_args '--help' do
66
66
  it "should output usage banner with string" do
67
- subject.should output(" test_rails3 [ARGUMENT1]")
67
+ expect(subject).to output(" test_rails3 [ARGUMENT1]")
68
68
  end
69
69
 
70
70
  it "should output usage banner with regexp" do
71
- subject.should output(/ test_rails3 /)
71
+ expect(subject).to output(/ test_rails3 /)
72
72
  end
73
73
  end
74
74
 
@@ -76,42 +76,42 @@ describe :test_rails3 do
76
76
  with_args :test_arg
77
77
 
78
78
  it "should generate file 'test_arg'" do
79
- subject.should generate('test_arg')
79
+ expect(subject).to generate('test_arg')
80
80
  end
81
81
  end
82
82
 
83
83
  with_args :test_arg do
84
84
  it "should generate file 'test_arg'" do
85
- subject.should generate('test_arg')
85
+ expect(subject).to generate('test_arg')
86
86
  end
87
87
 
88
88
  it "should not generate template_name" do
89
89
  # because that option hasn't been given in this context.
90
- subject.should_not generate('template_name')
90
+ expect(subject).not_to generate('template_name')
91
91
  end
92
92
 
93
93
  with_generator_options :behavior => :revoke do
94
94
  it "should delete file 'test_arg'" do
95
- subject.should generate {
96
- File.should_not exist("test_arg")
95
+ expect(subject).to generate {
96
+ expect(File).not_to exist("test_arg")
97
97
  }
98
98
  end
99
99
 
100
100
  # demonstrate use of the `delete` matcher, which is equivalent to
101
101
  # above:
102
102
  it "should destroy file 'test_arg'" do
103
- subject.should delete("test_arg")
103
+ expect(subject).to delete("test_arg")
104
104
  end
105
105
  end
106
106
 
107
107
  # ...and a test of nested args
108
108
  with_args "template_name" do
109
109
  it "should generate file 'test_arg'" do
110
- subject.should generate('test_arg')
110
+ expect(subject).to generate('test_arg')
111
111
  end
112
112
 
113
113
  it "should generate file 'template_name'" do
114
- subject.should generate("template_name")
114
+ expect(subject).to generate("template_name")
115
115
  end
116
116
  end
117
117
  end
@@ -10,8 +10,8 @@ describe GenSpec do
10
10
  after { GenSpec.root = nil }
11
11
 
12
12
  it "should generate files in generation root" do
13
- within_source_root { Dir[File.join(GenSpec.root, '**/*')].should_not be_empty }
14
- subject.should generate("a_directory")
13
+ within_source_root { expect(Dir[File.join(GenSpec.root, '**/*')]).not_to be_empty }
14
+ expect(subject).to generate("a_directory")
15
15
  end
16
16
  end
17
17
  end
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear_merged!
3
+
1
4
  # Having ./support in the load path means Rails will load the generators at
2
5
  # ./support/generators/**/*_generator.rb and
3
6
  # ./support/rails/generators/**/*_generator.rb
@@ -6,7 +9,7 @@ $LOAD_PATH.push File.join(File.dirname(__FILE__), "support")
6
9
  require 'bundler'
7
10
  Bundler.setup
8
11
 
9
- if ENV['USE_RAILS']
12
+ if ENV['RAILS_VERSION'] != 'none'
10
13
  require 'rails'
11
14
  require 'rails/generators'
12
15
  end
@@ -23,6 +26,10 @@ if !defined?(Rails)
23
26
  require File.expand_path('support/generators/question/question_generator', File.dirname(__FILE__))
24
27
  end
25
28
 
29
+ if RSpec::Expectations.respond_to?(:configuration)
30
+ RSpec::Expectations.configuration.on_potential_false_positives = :nothing
31
+ end
32
+
26
33
  RSpec.configure do |c|
27
34
  c.before { GenSpec.root = File.expand_path('../tmp', File.dirname(__FILE__)) } if RUBY_PLATFORM =~ /java/i
28
35
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Colin MacKenzie IV
@@ -14,53 +13,67 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: thor
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '2'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '4'
38
37
  type: :runtime
39
38
  prerelease: false
40
39
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
40
  requirements:
43
- - - ~>
41
+ - - ">="
44
42
  - !ruby/object:Gem::Version
45
43
  version: '2'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '4'
46
47
  - !ruby/object:Gem::Dependency
47
- name: sc-core-ext
48
+ name: coveralls
48
49
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
50
  requirements:
51
- - - ~>
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 1.2.1
54
- type: :runtime
53
+ version: '0'
54
+ type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
57
  requirements:
59
- - - ~>
58
+ - - ">="
60
59
  - !ruby/object:Gem::Version
61
- version: 1.2.1
62
- description: Simple, expressive Thor and/or Rails 3 generator testing for RSpec. For
63
- the Rails 2.3 version, use genspec 0.1.x.
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: Simple, expressive Thor and/or Rails 3+ generator testing for RSpec.
76
+ For the Rails 2.3 version, use genspec 0.1.x.
64
77
  email: sinisterchipmunk@gmail.com
65
78
  executables: []
66
79
  extensions: []
@@ -68,10 +81,10 @@ extra_rdoc_files:
68
81
  - LICENSE
69
82
  - README.rdoc
70
83
  files:
71
- - .document
72
- - .gitignore
73
- - .rspec
74
- - .travis.yml
84
+ - ".document"
85
+ - ".gitignore"
86
+ - ".rspec"
87
+ - ".travis.yml"
75
88
  - Gemfile
76
89
  - LICENSE
77
90
  - README.rdoc
@@ -99,38 +112,31 @@ files:
99
112
  - spec/support/generators/test_rails3/USAGE
100
113
  - spec/support/generators/test_rails3/templates/file
101
114
  - spec/support/generators/test_rails3/test_rails3_generator.rb
102
- homepage: http://www.thoughtsincomputation.com
115
+ homepage: http://github.com/sinisterchipmunk/genspec
103
116
  licenses: []
117
+ metadata: {}
104
118
  post_install_message:
105
119
  rdoc_options:
106
- - --charset=UTF-8
120
+ - "--charset=UTF-8"
107
121
  require_paths:
108
122
  - lib
109
123
  required_ruby_version: !ruby/object:Gem::Requirement
110
- none: false
111
124
  requirements:
112
- - - ! '>='
125
+ - - ">="
113
126
  - !ruby/object:Gem::Version
114
127
  version: '0'
115
- segments:
116
- - 0
117
- hash: -4044716062259480151
118
128
  required_rubygems_version: !ruby/object:Gem::Requirement
119
- none: false
120
129
  requirements:
121
- - - ! '>='
130
+ - - ">="
122
131
  - !ruby/object:Gem::Version
123
132
  version: '0'
124
- segments:
125
- - 0
126
- hash: -4044716062259480151
127
133
  requirements: []
128
134
  rubyforge_project:
129
- rubygems_version: 1.8.25
135
+ rubygems_version: 2.5.1
130
136
  signing_key:
131
- specification_version: 3
132
- summary: Simple, expressive Thor and/or Rails 3 generator testing for RSpec. For the
133
- Rails 2.3 version, use genspec 0.1.x.
137
+ specification_version: 4
138
+ summary: Simple, expressive Thor and/or Rails 3+ generator testing for RSpec. For
139
+ the Rails 2.3 version, use genspec 0.1.x.
134
140
  test_files:
135
141
  - spec/generators/migration_spec.rb
136
142
  - spec/generators/question_spec.rb