code-spec 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.document +0 -0
  2. data/.gitignore +0 -0
  3. data/.rspec +0 -0
  4. data/LICENSE +0 -0
  5. data/README.markdown +0 -0
  6. data/Rakefile +3 -3
  7. data/VERSION +1 -1
  8. data/code-spec.gemspec +14 -12
  9. data/lib/code-spec.rb +0 -0
  10. data/lib/code_spec/content_helpers.rb +0 -0
  11. data/lib/code_spec/core_ext.rb +0 -0
  12. data/lib/code_spec/matchers/content_matcher.rb +2 -2
  13. data/lib/code_spec/matchers/have_block.rb +0 -0
  14. data/lib/code_spec/matchers/have_call.rb +36 -20
  15. data/lib/code_spec/matchers/have_calls.rb +0 -0
  16. data/lib/code_spec/matchers/{have_module.rb → have_class_module.rb} +0 -0
  17. data/lib/code_spec/matchers/have_class_self.rb +0 -0
  18. data/lib/code_spec/matchers/have_comment.rb +0 -0
  19. data/lib/code_spec/matchers/have_content.rb +0 -0
  20. data/lib/code_spec/matchers/have_method.rb +6 -3
  21. data/lib/code_spec/matchers/have_region.rb +0 -0
  22. data/lib/code_spec/matchers/have_subclass.rb +7 -8
  23. data/lib/code_spec/matchers/include_module.rb +0 -0
  24. data/lib/code_spec/matchers/inherit_from.rb +0 -0
  25. data/lib/code_spec/matchers/match_lines.rb +0 -0
  26. data/spec/code-spec/fixtures/logfile.log +0 -0
  27. data/spec/code-spec/matchers/class_self_spec.rb +0 -0
  28. data/spec/code-spec/matchers/have_block_spec.rb +0 -0
  29. data/spec/code-spec/matchers/have_call_args.rb +13 -0
  30. data/spec/code-spec/matchers/have_call_spec.rb +28 -1
  31. data/spec/code-spec/matchers/have_calls_spec.rb +0 -0
  32. data/spec/code-spec/matchers/have_class_spec.rb +0 -0
  33. data/spec/code-spec/matchers/have_method_spec.rb +0 -0
  34. data/spec/code-spec/matchers/have_module_spec.rb +0 -0
  35. data/spec/code-spec/matchers/have_region_spec.rb +0 -0
  36. data/spec/code-spec/matchers/have_subclass_spec.rb +0 -0
  37. data/spec/code-spec/matchers/include_module_spec.rb +0 -0
  38. data/spec/code-spec/matchers/inherit_from_spec.rb +0 -0
  39. data/spec/code-spec/matchers/match_content_spec.rb +0 -0
  40. data/spec/spec_helper.rb +1 -2
  41. metadata +12 -11
data/.document CHANGED
File without changes
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/LICENSE CHANGED
File without changes
data/README.markdown CHANGED
File without changes
data/Rakefile CHANGED
@@ -7,9 +7,9 @@ begin
7
7
  gem.email = "kmandrup@gmail.com"
8
8
  gem.homepage = "http://github.com/kristianmandrup/code-spec"
9
9
  gem.authors = ["Kristian Mandrup"]
10
- gem.add_development_dependency "rspec", ">= 2.0.0.beta.19"
11
- gem.add_dependency "require_all", ">= 1.1.0"
12
- gem.add_dependency "activesupport", ">= 3.0.0.rc"
10
+ gem.add_development_dependency "rspec", "~> 2.0.0.beta.22"
11
+ gem.add_dependency "require_all", "~> 1.1.0"
12
+ gem.add_dependency "activesupport", "~> 3.0.0"
13
13
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
14
  end
15
15
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/code-spec.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{code-spec}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.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"]
12
- s.date = %q{2010-08-19}
12
+ s.date = %q{2010-09-16}
13
13
  s.description = %q{Code file RSpec 2 matchers that make it easy to spec Ruby code files, fx updated or generated by a Thor generator}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -32,11 +32,11 @@ Gem::Specification.new do |s|
32
32
  "lib/code_spec/matchers/have_block.rb",
33
33
  "lib/code_spec/matchers/have_call.rb",
34
34
  "lib/code_spec/matchers/have_calls.rb",
35
+ "lib/code_spec/matchers/have_class_module.rb",
35
36
  "lib/code_spec/matchers/have_class_self.rb",
36
37
  "lib/code_spec/matchers/have_comment.rb",
37
38
  "lib/code_spec/matchers/have_content.rb",
38
39
  "lib/code_spec/matchers/have_method.rb",
39
- "lib/code_spec/matchers/have_module.rb",
40
40
  "lib/code_spec/matchers/have_region.rb",
41
41
  "lib/code_spec/matchers/have_subclass.rb",
42
42
  "lib/code_spec/matchers/include_module.rb",
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  "spec/code-spec/fixtures/logfile.log",
46
46
  "spec/code-spec/matchers/class_self_spec.rb",
47
47
  "spec/code-spec/matchers/have_block_spec.rb",
48
+ "spec/code-spec/matchers/have_call_args.rb",
48
49
  "spec/code-spec/matchers/have_call_spec.rb",
49
50
  "spec/code-spec/matchers/have_calls_spec.rb",
50
51
  "spec/code-spec/matchers/have_class_spec.rb",
@@ -65,6 +66,7 @@ Gem::Specification.new do |s|
65
66
  s.test_files = [
66
67
  "spec/code-spec/matchers/class_self_spec.rb",
67
68
  "spec/code-spec/matchers/have_block_spec.rb",
69
+ "spec/code-spec/matchers/have_call_args.rb",
68
70
  "spec/code-spec/matchers/have_call_spec.rb",
69
71
  "spec/code-spec/matchers/have_calls_spec.rb",
70
72
  "spec/code-spec/matchers/have_class_spec.rb",
@@ -83,18 +85,18 @@ Gem::Specification.new do |s|
83
85
  s.specification_version = 3
84
86
 
85
87
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
86
- s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
87
- s.add_runtime_dependency(%q<require_all>, [">= 1.1.0"])
88
- s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.rc"])
88
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
89
+ s.add_runtime_dependency(%q<require_all>, ["~> 1.1.0"])
90
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
89
91
  else
90
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
91
- s.add_dependency(%q<require_all>, [">= 1.1.0"])
92
- s.add_dependency(%q<activesupport>, [">= 3.0.0.rc"])
92
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
93
+ s.add_dependency(%q<require_all>, ["~> 1.1.0"])
94
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
93
95
  end
94
96
  else
95
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
96
- s.add_dependency(%q<require_all>, [">= 1.1.0"])
97
- s.add_dependency(%q<activesupport>, [">= 3.0.0.rc"])
97
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
98
+ s.add_dependency(%q<require_all>, ["~> 1.1.0"])
99
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
98
100
  end
99
101
  end
100
102
 
data/lib/code-spec.rb CHANGED
File without changes
File without changes
File without changes
@@ -22,7 +22,7 @@ module RSpec
22
22
  @content = content
23
23
  match = is_match? content
24
24
  content_to_yield = if indexes
25
- content_matches[indexes.first] || content_matches[indexes.last]
25
+ content_matches[indexes.last] || content_matches[indexes.first]
26
26
  else
27
27
  content_matches[index]
28
28
  end
@@ -75,7 +75,7 @@ module RSpec
75
75
  OPT_SPACES + OPT_ARGS
76
76
  end
77
77
 
78
- def args_expr
78
+ def args_expr
79
79
  args ? OPT_SPACES + opt(LPAR) + OPT_SPACES + "#{args}" + OPT_SPACES + opt(RPAR) : ''
80
80
  end
81
81
 
File without changes
@@ -7,27 +7,43 @@
7
7
  #
8
8
  module RSpec::RubyContentMatchers
9
9
  class HaveCall < RSpec::RubyContentMatcher
10
- attr_reader :method, :args, :dot, :content
10
+ attr_accessor :method_name, :args, :dot, :content
11
11
 
12
- def initialize(method, options = {})
13
- @method = method.to_s
14
- @args = case options
15
- when Hash
12
+ def initialize(method_name, options = {})
13
+ self.method_name = method_name.to_s
14
+ self.args = case options
15
+ when Hash
16
+ self.dot = options[:dot]
16
17
  options[:args]
17
18
  else
18
- options
19
+ (options == {}) ? nil : options
19
20
  end
20
- @dot = options[:dot]
21
+
22
+ self.args = ":#{args}" if args.kind_of? Symbol
21
23
  end
22
24
 
23
25
  def matches?(content)
24
26
  @content = content
25
- has_def = (content =~ /def(.*)#{method}/)
26
- expr = if has_def || dot == :form
27
- /#{dot_expr}#{method}#{args_expr}/m
27
+ def_pos = (content =~ /def(.*)#{method_name}/) || 999
28
+ call_pos = (content =~ /[^def]?#{method_name}/) || 999
29
+
30
+ arguments_expr = case args
31
+ when String
32
+ args_expr
33
+ when Array
34
+ args.inject("") do |res, arg|
35
+ res << '(\s|,|\w|:)*' + arg.inspect
36
+ end
37
+ else
38
+ return nil
39
+ end
40
+
41
+ expr = if (def_pos < call_pos) || dot == :form
42
+ /#{dot_expr}#{method_name}#{arguments_expr}/m
28
43
  else
29
- /#{dot_expr}?#{method}#{args_expr}/m
30
- end
44
+ /#{dot_expr}?#{method_name}#{arguments_expr}/m
45
+ end
46
+ @expr = expr
31
47
  debug "expr = #{expr}"
32
48
  debug "content = %{#{content}}"
33
49
  debug "content =~ #{expr}"
@@ -36,12 +52,12 @@ module RSpec::RubyContentMatchers
36
52
 
37
53
  def failure_message
38
54
  super
39
- "Expected there to be a call to #{method}#{args_msg}, but there wasn't"
55
+ "Expected there to be a call to #{method_name}#{args_msg}, but there wasn't. Regexp: #{@expr} did not match\n#{@content}"
40
56
  end
41
57
 
42
58
  def negative_failure_message
43
59
  super
44
- "Did not expect there to be a call to #{method}#{args_msg}, but there was"
60
+ "Did not expect there to be a call to #{method_name}#{args_msg}, but there was"
45
61
  end
46
62
 
47
63
  protected
@@ -63,16 +79,16 @@ module RSpec::RubyContentMatchers
63
79
 
64
80
  end
65
81
 
66
- def have_call(method, options = {})
67
- HaveCall.new(method, options)
82
+ def have_call(method_name, options = {})
83
+ HaveCall.new(method_name, options)
68
84
  end
69
85
 
70
- def have_dot_call(method, options = {})
71
- have_call method, options.merge(:dot => true)
86
+ def have_dot_call(method_name, options = {})
87
+ have_call method_name, options.merge(:dot => true)
72
88
  end
73
89
 
74
- def have_form_call(method, options = {})
75
- have_call method, options.merge(:dot => :form)
90
+ def have_form_call(method_name, options = {})
91
+ have_call method_name, options.merge(:dot => :form)
76
92
  end
77
93
 
78
94
  end
File without changes
File without changes
File without changes
File without changes
@@ -51,16 +51,19 @@ module RSpec::RubyContentMatchers
51
51
 
52
52
  def alt_end
53
53
  'def'
54
- end
55
-
54
+ end
56
55
  end
57
56
 
58
57
  def have_method(method, type = nil)
59
58
  HaveMethod.new(method, type)
60
59
  end
61
60
 
61
+ def have_class_method(method)
62
+ have_method method, :class
63
+ end
64
+
62
65
  def have_args_method(method, options = {})
63
- HaveMethod.new(method, options[:type], options)
66
+ have_method method, options[:type], options
64
67
  end
65
68
 
66
69
  end
File without changes
@@ -1,22 +1,23 @@
1
1
  module RSpec::RubyContentMatchers
2
2
  class HaveSubclass < RSpec::RubyContentMatcher
3
- attr_reader :klass, :superclass, :type
3
+ attr_reader :klass, :superclass, :type, :full_class
4
4
 
5
5
  def initialize(klass, superclass, type=nil)
6
- @klass = klass.to_s.camelize
6
+ @klass = klass.to_s.camelize
7
7
  super @klass
8
8
  @superclass = superclass.to_s.camelize
9
- @type = type.to_s.camelize if type
9
+ @type = type.to_s.camelize if type
10
+ @full_class = "#{@klass}#{@type}"
10
11
  end
11
12
 
12
13
  def failure_message
13
14
  super
14
- "Expected there to be the subclass #{klass} of #{superclass}"
15
+ "Expected there to be the subclass #{full_class} of #{superclass}"
15
16
  end
16
17
 
17
18
  def negative_failure_message
18
19
  super
19
- "Did no expected there to be the subclass #{klass} of #{superclass}"
20
+ "Did no expected there to be the subclass #{full_class} of #{superclass}"
20
21
  end
21
22
 
22
23
  protected
@@ -34,7 +35,5 @@ module RSpec::RubyContentMatchers
34
35
  def have_subclass(klass, superclass, type=nil)
35
36
  HaveSubclass.new(klass, superclass, type)
36
37
  end
37
- alias_method :be_subclass, :have_subclass
38
-
39
-
38
+ alias_method :be_subclass, :have_subclass
40
39
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'method call matcher with args' do
4
+ context "content with call hello" do
5
+ call = %{
6
+ devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
7
+ }
8
+ it "should have call to hello" do
9
+ call.should have_call :devise, :args => [:confirmable, :trackable]
10
+ call.should_not have_call :devise, :args => [:confirmable, :trackable_ids]
11
+ end
12
+ end
13
+ end
@@ -16,7 +16,7 @@ describe 'method call matcher' do
16
16
  it "should have call to hello" do
17
17
  call.should have_call :hello
18
18
  end
19
- end
19
+ end
20
20
 
21
21
  context "content with call hello" do
22
22
  call = %q{
@@ -42,6 +42,33 @@ describe 'method call matcher' do
42
42
  clazz.should have_call :role_strategy, :args => ':admin_flag'
43
43
  end
44
44
  end
45
+
46
+ context "Migration should have usual structure" do
47
+ migration_klass = %q{
48
+ class DoColumns < ActiveRecord::Migration
49
+ def self.up
50
+ create_table :users do |t|
51
+ t.string :name
52
+ t.integer :age
53
+ t.boolean :admin
54
+ end
55
+ end
56
+
57
+ def self.down
58
+ drop_table :users
59
+ end
60
+ end}
61
+
62
+ it "should have call to role_strategy with args :admin_flag" do
63
+ migration_klass.should have_class_method :up
64
+
65
+ migration_klass.should have_class_method :down do |down|
66
+ puts down
67
+ down.should have_call 'drop_table', :users
68
+ end
69
+
70
+ end
71
+ end
45
72
  end
46
73
 
47
74
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'rspec'
2
- require 'rspec/autorun'
1
+ require 'rspec/core'
3
2
  require 'code-spec'
4
3
 
5
4
  def fixtures_dir
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-19 00:00:00 +02:00
17
+ date: 2010-09-16 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,15 +23,15 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 2
30
30
  - 0
31
31
  - 0
32
32
  - beta
33
- - 19
34
- version: 2.0.0.beta.19
33
+ - 22
34
+ version: 2.0.0.beta.22
35
35
  type: :development
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ">="
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  segments:
46
46
  - 1
@@ -55,14 +55,13 @@ dependencies:
55
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
- - - ">="
58
+ - - ~>
59
59
  - !ruby/object:Gem::Version
60
60
  segments:
61
61
  - 3
62
62
  - 0
63
63
  - 0
64
- - rc
65
- version: 3.0.0.rc
64
+ version: 3.0.0
66
65
  type: :runtime
67
66
  version_requirements: *id003
68
67
  description: Code file RSpec 2 matchers that make it easy to spec Ruby code files, fx updated or generated by a Thor generator
@@ -90,11 +89,11 @@ files:
90
89
  - lib/code_spec/matchers/have_block.rb
91
90
  - lib/code_spec/matchers/have_call.rb
92
91
  - lib/code_spec/matchers/have_calls.rb
92
+ - lib/code_spec/matchers/have_class_module.rb
93
93
  - lib/code_spec/matchers/have_class_self.rb
94
94
  - lib/code_spec/matchers/have_comment.rb
95
95
  - lib/code_spec/matchers/have_content.rb
96
96
  - lib/code_spec/matchers/have_method.rb
97
- - lib/code_spec/matchers/have_module.rb
98
97
  - lib/code_spec/matchers/have_region.rb
99
98
  - lib/code_spec/matchers/have_subclass.rb
100
99
  - lib/code_spec/matchers/include_module.rb
@@ -103,6 +102,7 @@ files:
103
102
  - spec/code-spec/fixtures/logfile.log
104
103
  - spec/code-spec/matchers/class_self_spec.rb
105
104
  - spec/code-spec/matchers/have_block_spec.rb
105
+ - spec/code-spec/matchers/have_call_args.rb
106
106
  - spec/code-spec/matchers/have_call_spec.rb
107
107
  - spec/code-spec/matchers/have_calls_spec.rb
108
108
  - spec/code-spec/matchers/have_class_spec.rb
@@ -149,6 +149,7 @@ summary: Code file RSpec 2 matchers
149
149
  test_files:
150
150
  - spec/code-spec/matchers/class_self_spec.rb
151
151
  - spec/code-spec/matchers/have_block_spec.rb
152
+ - spec/code-spec/matchers/have_call_args.rb
152
153
  - spec/code-spec/matchers/have_call_spec.rb
153
154
  - spec/code-spec/matchers/have_calls_spec.rb
154
155
  - spec/code-spec/matchers/have_class_spec.rb