generator-spec 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{generator-spec}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
@@ -7,6 +7,12 @@ require 'rspec_for_generators/rails_spec_helper'
7
7
  # Call configure to load the settings from
8
8
  # Rails.application.config.generators to Rails::Generators
9
9
 
10
+ class Array
11
+ def args
12
+ flatten.map(&:to_s)
13
+ end
14
+ end
15
+
10
16
  # require the generators
11
17
  def require_generators *generator_list
12
18
  req = RSpec::Generator::Require
@@ -1,6 +1,6 @@
1
1
  module RSpec::RubyContentMatchers
2
2
  class HaveBlock
3
- attr_reader :name, :args, :block_args
3
+ attr_reader :name, :args, :block_args, :content
4
4
 
5
5
  def initialize(name, options={})
6
6
  @name = name.to_s
@@ -9,21 +9,23 @@ module RSpec::RubyContentMatchers
9
9
  end
10
10
 
11
11
  def matches?(content)
12
- match_res = (content =~ /#{name}\s+#{args_expr}do\s+#{block_args_expr}(.*?)end/m)
12
+ @content = content
13
+ match_res = (content =~ /#{name}\s+#{args_expr}do\s+#{block_args_expr}(.*?)end/m) != nil
13
14
  block_content = $1 || $3
14
15
  if block_given? && block_content
15
16
  ruby_content = block_content.strip.extend(RSpec::RubyContent::Helpers)
16
17
  yield ruby_content
17
- else
18
- match_res
19
18
  end
19
+ match_res
20
20
  end
21
21
 
22
- def failure_message
22
+ def failure_message
23
+ puts "Content: #{content}" if RSpec::Generator.debug?
23
24
  return "Expected there to be a block #{name} with arguments #{args}, but there wasn't"
24
25
  end
25
26
 
26
- def negative_failure_message
27
+ def negative_failure_message
28
+ puts "Content: #{content}" if RSpec::Generator.debug?
27
29
  return "Did not expect there to be a block #{name} with arguments #{args}, but there was"
28
30
  end
29
31
 
@@ -7,7 +7,7 @@
7
7
  #
8
8
  module RSpec::RubyContentMatchers
9
9
  class HaveCall
10
- attr_reader :method, :args
10
+ attr_reader :method, :args, :content
11
11
 
12
12
  def initialize(method, args = nil)
13
13
  @method = method.to_s
@@ -15,15 +15,18 @@ module RSpec::RubyContentMatchers
15
15
  end
16
16
 
17
17
  def matches?(content)
18
- content =~ /#{method}\s+#{args_expr}/m
18
+ @content = content
19
+ (content =~ /#{method}#{args_expr}/m) != nil
19
20
  end
20
21
 
21
22
  def failure_message
23
+ puts "Content: #{content}" if RSpec::Generator.debug?
22
24
  return "Expected there to be a call to #{method} with args #{args}, but there wasn't" if args
23
- "Expected there to be a call to #{method}, but there wasn't"
25
+ "Expected there to be a call to #{method}, but there wasn't"
24
26
  end
25
27
 
26
- def negative_failure_message
28
+ def negative_failure_message
29
+ puts "Content: #{content}" if RSpec::Generator.debug?
27
30
  return "Did not expect there to be a call to #{method} with args #{args}, but there was" if args
28
31
  "Did not expect there to be a call to #{method}, but there was"
29
32
  end
@@ -31,7 +34,7 @@ module RSpec::RubyContentMatchers
31
34
  protected
32
35
 
33
36
  def args_expr
34
- args ? "(\()?\s*#{args}\s*(\))?" : ''
37
+ args ? "\s+(\()?\s*#{args}\s*(\))?" : ''
35
38
  end
36
39
 
37
40
  end
@@ -1,13 +1,13 @@
1
1
  module RSpec::RubyContentMatchers
2
2
  class HaveCalls
3
- attr_reader :calls
4
- attr_accessor :method, :args
3
+ attr_reader :calls, :method, :args, :content
5
4
 
6
5
  def initialize(calls)
7
6
  @calls = calls
8
7
  end
9
8
 
10
9
  def matches?(content)
10
+ @content = content
11
11
  calls.each_pair do |method, args|
12
12
  @method = method.to_s
13
13
  @args = args
@@ -17,11 +17,13 @@ module RSpec::RubyContentMatchers
17
17
  end
18
18
 
19
19
  def failure_message
20
+ puts "Content: #{content}" if RSpec::Generator.debug?
20
21
  return "Expected there to be a call to #{method} with args #{args}, but there wasn't" if args
21
22
  "Expected there to be a call to #{method}, but there wasn't"
22
23
  end
23
24
 
24
- def negative_failure_message
25
+ def negative_failure_message
26
+ puts "Content: #{content}" if RSpec::Generator.debug?
25
27
  return "Did not expect there to be a call to #{method} with args #{args}, but there was" if args
26
28
  "Did not expect there to be a call to #{method}, but there was"
27
29
  end
@@ -1,27 +1,29 @@
1
1
  module RSpec::RubyContentMatchers
2
2
  class HaveClass
3
- attr_reader :klass, :type
3
+ attr_reader :klass, :type, :content
4
4
 
5
5
  def initialize(klass, type=nil)
6
6
  @klass = klass.to_s.camelize
7
7
  @type = type.to_s.camelize if type
8
8
  end
9
9
 
10
- def matches?(content)
10
+ def matches?(content)
11
+ @content = content
11
12
  match_res = (content =~ /class\s+#{klass}#{type}\s+(.*)end/m)
12
13
  if block_given? && $1
13
14
  ruby_content = $1.strip.extend(RSpec::RubyContent::Helpers)
14
- yield ruby_content
15
- else
16
- match_res
15
+ yield ruby_content
17
16
  end
17
+ match_res
18
18
  end
19
19
 
20
- def failure_message
20
+ def failure_message
21
+ puts "Content: #{content}" if RSpec::Generator.debug?
21
22
  "Expected there to be the class #{klass}"
22
23
  end
23
24
 
24
- def negative_failure_message
25
+ def negative_failure_message
26
+ puts "Content: #{content}" if RSpec::Generator.debug?
25
27
  "Did no expected there to be the class #{klass}"
26
28
  end
27
29
 
@@ -7,14 +7,15 @@
7
7
  #
8
8
  module RSpec::RubyContentMatchers
9
9
  class HaveMethod
10
- attr_reader :method, :type
10
+ attr_reader :method, :type, :content
11
11
 
12
12
  def initialize(method, type=nil)
13
13
  @method = method.to_s
14
14
  @type = type
15
15
  end
16
16
 
17
- def matches?(content)
17
+ def matches?(content)
18
+ @content = content
18
19
  match_res = case type
19
20
  when :class
20
21
  content =~ /def\s+self.#{method}\s*(\(.+\))?(.*?)(def|end)/m
@@ -24,19 +25,20 @@ module RSpec::RubyContentMatchers
24
25
  if block_given? && $2
25
26
  ruby_content = $2.strip.extend(RSpec::RubyContent::Helpers)
26
27
  ruby_content << "\nend" if !(ruby_content =~ /\nend$/)
27
- yield ruby_content
28
- else
29
- match_res
28
+ yield ruby_content
30
29
  end
30
+ match_res
31
31
  end
32
32
 
33
33
  def failure_message
34
+ puts "Content: #{content}" if RSpec::Generator.debug?
34
35
  return "Expected there to be the class method #{method}, but there wasn't" if type == :class
35
36
  "Expected there to be the method #{method}, but there wasn't"
36
37
  end
37
38
 
38
39
  def negative_failure_message
39
- return "Did not expect there to be the method #{method}, but there was" if type == :class
40
+ puts "Content: #{content}" if RSpec::Generator.debug?
41
+ return "Did not expect there to be the class method #{method}, but there was" if type == :class
40
42
  "Did not expect there to be the method #{method}, but there was"
41
43
  end
42
44
 
@@ -1,12 +1,13 @@
1
1
  module RSpec::RubyContentMatchers
2
2
  class HaveModule
3
- attr_reader :module_name
3
+ attr_reader :module_name, :content
4
4
 
5
5
  def initialize(module_name)
6
6
  @module_name = module_name.to_s.camelize
7
7
  end
8
8
 
9
9
  def matches?(content)
10
+ @content = content
10
11
  match_res =~ /module\s+#{module_name}\s+(.*)end/m
11
12
  if block_given? && match_res
12
13
  ruby_content = $2.strip.extend(RSpec::RubyContent::Helpers)
@@ -17,10 +18,12 @@ module RSpec::RubyContentMatchers
17
18
  end
18
19
 
19
20
  def failure_message
21
+ puts "Content: #{content}" if RSpec::Generator.debug?
20
22
  "Expected there to be the module #{module_name}"
21
23
  end
22
24
 
23
25
  def negative_failure_message
26
+ puts "Content: #{content}" if RSpec::Generator.debug?
24
27
  "Did no expected there to be the module #{module_name}"
25
28
  end
26
29
 
@@ -1,6 +1,6 @@
1
1
  module RSpec::RubyContentMatchers
2
2
  class HaveSubclass
3
- attr_reader :klass, :superclass, :type
3
+ attr_reader :klass, :superclass, :type, :content
4
4
 
5
5
  def initialize(klass, superclass, type=nil)
6
6
  @klass = klass.to_s.camelize
@@ -9,6 +9,7 @@ module RSpec::RubyContentMatchers
9
9
  end
10
10
 
11
11
  def matches?(content)
12
+ @content = content
12
13
  match_res = (content =~ /class\s+#{klass}#{type}\s+<\s+#{superclass}(.*)end$/m)
13
14
  if block_given? && $1
14
15
  ruby_content = $1.strip.extend(RSpec::RubyContent::Helpers)
@@ -18,11 +19,13 @@ module RSpec::RubyContentMatchers
18
19
  end
19
20
  end
20
21
 
21
- def failure_message
22
+ def failure_message
23
+ puts "Content: #{content}" if RSpec::Generator.debug?
22
24
  "Expected there to be the subclass #{klass} of #{superclass}"
23
25
  end
24
26
 
25
27
  def negative_failure_message
28
+ puts "Content: #{content}" if RSpec::Generator.debug?
26
29
  "Did no expected there to be the subclass #{klass} of #{superclass}"
27
30
  end
28
31
  end
@@ -1,12 +1,13 @@
1
1
  module RSpec::RubyContentMatchers
2
2
  class IncludeModule
3
- attr_reader :module_name
3
+ attr_reader :module_name, :content
4
4
 
5
5
  def initialize module_name
6
6
  @module_name = module_name.to_s.camelize
7
7
  end
8
8
 
9
9
  def matches?(content)
10
+ @content = content
10
11
  match_res = (content =~ /include\s+#{module_name}/)
11
12
  if block_given? && match_res
12
13
  ruby_content = content.extend(RSpec::RubyContent::Helpers)
@@ -17,10 +18,12 @@ module RSpec::RubyContentMatchers
17
18
  end
18
19
 
19
20
  def failure_message
21
+ puts "Content: #{content}" if RSpec::Generator.debug?
20
22
  "Expected there to be an inclusion of module #{module_name}"
21
23
  end
22
24
 
23
25
  def negative_failure_message
26
+ puts "Content: #{content}" if RSpec::Generator.debug?
24
27
  "Did not expect there to be an inclusion of module #{module_name}"
25
28
  end
26
29
 
@@ -32,12 +32,12 @@ describe 'helper_generator' do
32
32
 
33
33
  it "should decorate an existing Account helper file with a 'help_me' method" do
34
34
  with_generator do |g|
35
- name = 'account'
36
- create_helper name do
35
+ name = :account
36
+ create_helper :account do
37
37
  '# helper content'
38
38
  end
39
- g.run_generator [name]
40
- g.should generate_helper name do |content|
39
+ g.run_generator [:account].args
40
+ g.should generate_helper :account do |content|
41
41
  content.should have_helper_class name do |klass|
42
42
  klass.should have_method :help_me
43
43
  end
@@ -1,4 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ RSpec::Generator.debug = true
4
+
2
5
  require_generator :migration
3
6
 
4
7
  describe 'migration_generator' do
@@ -16,14 +19,14 @@ describe 'migration_generator' do
16
19
 
17
20
  it "should generate create_user migration" do
18
21
  with_generator do |g|
19
- name = :create_users
20
- remove_migration :create_users
21
- g.run_generator [name.to_s]
22
- g.should generate_migration name do |content|
23
- content.should have_migration name do |klass|
22
+ # remove_migration :create_users
23
+ # g.run_generator [:create_users].args
24
+ g.should generate_migration :create_users do |content|
25
+ content.should have_migration :create_users do |klass|
24
26
  klass.should have_up do |up|
25
27
  up.should have_create_table :users do |user_tbl|
26
28
  user_tbl.should have_columns :name => :string, :age => :string
29
+ user_tbl.should have_timestamps
27
30
  end
28
31
  end
29
32
 
@@ -2,7 +2,7 @@ require 'rspec'
2
2
  require 'rspec/autorun'
3
3
  require 'rspec_for_generators'
4
4
 
5
- RSpec::Generator.remove_temp_dir = true
5
+ RSpec::Generator.remove_temp_dir = false # true
6
6
  RSpec::Generator.configure_root_dir __FILE__
7
7
 
8
8
  module Rails
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 1
9
- version: 0.4.1
8
+ - 2
9
+ version: 0.4.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup