code-spec 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -9,6 +9,7 @@ begin
9
9
  gem.authors = ["Kristian Mandrup"]
10
10
  gem.add_development_dependency "rspec", "~> 2.0.0.beta.22"
11
11
  gem.add_dependency "require_all", "~> 1.1.0"
12
+ gem.add_dependency "sugar-high", "~> 0.2.10"
12
13
  gem.add_dependency "activesupport", "~> 3.0.0"
13
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
15
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
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.3"
8
+ s.version = "0.2.4"
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-09-16}
12
+ s.date = %q{2010-09-18}
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 = [
@@ -42,6 +42,8 @@ Gem::Specification.new do |s|
42
42
  "lib/code_spec/matchers/include_module.rb",
43
43
  "lib/code_spec/matchers/inherit_from.rb",
44
44
  "lib/code_spec/matchers/match_lines.rb",
45
+ "lib/code_spec/matchers/multi/have_classes_modules.rb",
46
+ "lib/code_spec/matchers/multi/have_methods.rb",
45
47
  "spec/code-spec/fixtures/logfile.log",
46
48
  "spec/code-spec/matchers/class_self_spec.rb",
47
49
  "spec/code-spec/matchers/have_block_spec.rb",
@@ -56,6 +58,9 @@ Gem::Specification.new do |s|
56
58
  "spec/code-spec/matchers/include_module_spec.rb",
57
59
  "spec/code-spec/matchers/inherit_from_spec.rb",
58
60
  "spec/code-spec/matchers/match_content_spec.rb",
61
+ "spec/code-spec/matchers/multi/have_classes_spec.rb",
62
+ "spec/code-spec/matchers/multi/have_methods_spec.rb",
63
+ "spec/code-spec/matchers/multi/have_modules_spec.rb",
59
64
  "spec/spec_helper.rb"
60
65
  ]
61
66
  s.homepage = %q{http://github.com/kristianmandrup/code-spec}
@@ -77,6 +82,9 @@ Gem::Specification.new do |s|
77
82
  "spec/code-spec/matchers/include_module_spec.rb",
78
83
  "spec/code-spec/matchers/inherit_from_spec.rb",
79
84
  "spec/code-spec/matchers/match_content_spec.rb",
85
+ "spec/code-spec/matchers/multi/have_classes_spec.rb",
86
+ "spec/code-spec/matchers/multi/have_methods_spec.rb",
87
+ "spec/code-spec/matchers/multi/have_modules_spec.rb",
80
88
  "spec/spec_helper.rb"
81
89
  ]
82
90
 
@@ -87,15 +95,18 @@ Gem::Specification.new do |s|
87
95
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
88
96
  s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
89
97
  s.add_runtime_dependency(%q<require_all>, ["~> 1.1.0"])
98
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.10"])
90
99
  s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
91
100
  else
92
101
  s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
93
102
  s.add_dependency(%q<require_all>, ["~> 1.1.0"])
103
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.10"])
94
104
  s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
95
105
  end
96
106
  else
97
107
  s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
98
108
  s.add_dependency(%q<require_all>, ["~> 1.1.0"])
109
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.10"])
99
110
  s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
100
111
  end
101
112
  end
data/lib/code-spec.rb CHANGED
@@ -1,6 +1,8 @@
1
- require 'rspec'
1
+ require 'rspec/core'
2
2
  require 'require_all'
3
3
  require 'active_support/inflector'
4
+ require 'sugar-high/arguments'
5
+ require 'sugar-high/array'
4
6
 
5
7
  module RSpec
6
8
  module RubyContentMatchers
@@ -31,7 +31,7 @@ module RSpec::RubyContentMatchers
31
31
  when String
32
32
  args_expr
33
33
  when Array
34
- args.inject("") do |res, arg|
34
+ args.flatten.inject("") do |res, arg|
35
35
  arg_val = (arg.kind_of?(String) && arg[0] == '#') ? arg[1..-1] : arg.inspect
36
36
  res << '(\s|,|\w|:)*' + arg_val
37
37
  end
@@ -0,0 +1,73 @@
1
+ module RSpec::RubyContentMatchers
2
+ class HaveModules < RSpec::RubyContentMatcher
3
+ attr_reader :name, :names, :type, :postfix
4
+
5
+ def initialize(*names)
6
+ postfix = last_arg_value({:postfix => ''}, names)
7
+ @names = names.to_strings
8
+ @postfix = postfix.to_s.camelize if postfix
9
+ @type = :module
10
+ end
11
+
12
+ def matches? content, &block
13
+ return false if names.empty?
14
+
15
+ @content = content
16
+
17
+ names.each do |name|
18
+ @name = name.camelize
19
+ @end_option = name
20
+ match = is_match? content
21
+ return false if !match
22
+ end
23
+ true
24
+ end
25
+
26
+ def is_match? content
27
+ expr = get_expr(content)
28
+ debug "match expression: #{expr}"
29
+ match = (content =~ expr)
30
+ @content_matches = [$1, $2, $3]
31
+ match
32
+ end
33
+
34
+ def failure_message
35
+ super
36
+ "Expected there to be the #{type} #{name}"
37
+ end
38
+
39
+ def negative_failure_message
40
+ super
41
+ "Did not expected there to be the #{type} #{name}"
42
+ end
43
+
44
+ protected
45
+
46
+ def main_expr
47
+ "#{type}" + SPACES + "#{name}#{postfix}" + SPACES + ANY_GROUP
48
+ end
49
+
50
+ def alt_end
51
+ type
52
+ end
53
+ end
54
+
55
+ class HaveClasses < HaveModules
56
+
57
+ def initialize *names
58
+ super *names
59
+ @type = :class
60
+ end
61
+ end
62
+
63
+ # can take :postfix hash arg
64
+ def have_modules *names
65
+ HaveModules.new names
66
+ end
67
+
68
+ # can take :postfix hash arg
69
+ def have_classes *names
70
+ HaveClasses.new *names
71
+ end
72
+
73
+ end
@@ -0,0 +1,85 @@
1
+ # This method tries to see if a specific method is contained in the generated file.
2
+ # It can operate (should) on either a file name or the raw content
3
+ #
4
+ # generated_file_name.should have_method "hello" # 'my/path/say_hello.rb'.should have_method "hello"
5
+ #
6
+ # say_hello_file_content.should have_method "hello"
7
+ #
8
+ module RSpec::RubyContentMatchers
9
+ class HaveMethods < RSpec::RubyContentMatcher
10
+ attr_reader :method, :type, :args, :names
11
+
12
+ def initialize *methods
13
+ options = last_option methods
14
+ @names = methods.to_strings
15
+ @type = options[:type]
16
+ @args = options[:args]
17
+ end
18
+
19
+ def matches? content, &block
20
+ return false if names.empty?
21
+
22
+ @content = content
23
+ names.each do |name|
24
+ @method = name
25
+ @end_option = name
26
+ match = is_match? content
27
+ return false if !match
28
+ end
29
+ true
30
+ end
31
+
32
+ def is_match? content
33
+ expr = get_expr(content)
34
+ debug "match expression: #{expr}"
35
+ match = (content =~ expr)
36
+ @content_matches = [$1, $2, $3]
37
+ match
38
+ end
39
+
40
+ def index
41
+ 1
42
+ end
43
+
44
+ def failure_message
45
+ super
46
+ "Expected there to be the #{class_msg} method #{method}, but there wasn't"
47
+ end
48
+
49
+ def negative_failure_message
50
+ super
51
+ "Did not expect there to be the #{class_msg} method #{method}, but there was"
52
+ end
53
+
54
+ protected
55
+
56
+ def class_msg
57
+ (type == :class) ? 'class' : ''
58
+ end
59
+
60
+ def main_expr
61
+ 'def' + SPACES + "#{self_expr}#{method}#{args_expr}" + ANY_GROUP
62
+ end
63
+
64
+ def args_expr
65
+ return super if args
66
+ any_args_expr
67
+ end
68
+
69
+ def self_expr
70
+ type == :class ? 'self.' : ''
71
+ end
72
+
73
+ def alt_end
74
+ 'def'
75
+ end
76
+ end
77
+
78
+ def have_methods *methods
79
+ HaveMethods.new methods
80
+ end
81
+
82
+ def have_class_methods *methods
83
+ have_methods *methods, :type => :class
84
+ end
85
+ end
@@ -17,6 +17,7 @@ describe 'method call matcher with args' do
17
17
  }
18
18
  it "should have call to hello" do
19
19
  call.should have_call :devise, :args => ['#confirm_me', "hello"]
20
+ call.should have_call :devise, :args => [['#confirm_me', "hello"]]
20
21
  call.should_not have_call :devise, :args => ['#hello']
21
22
  end
22
23
  end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'classes matcher' do
4
+ context "no class" do
5
+ no_class = %q{
6
+ module X
7
+ hello
8
+ hi
9
+ end
10
+ }
11
+
12
+ it "should not have class X" do
13
+ no_class.should_not have_classes :x
14
+ end
15
+ end
16
+
17
+ context "content with class X" do
18
+ class_x = %q{
19
+ class X
20
+ def hello
21
+ blip
22
+ end
23
+ end
24
+ }
25
+ it "should have class x" do
26
+ class_x.should have_classes [:x]
27
+ class_x.should_not have_classes :x, :y
28
+ end
29
+ end
30
+
31
+ context "content with class X and Y" do
32
+ classs_x_y = %q{
33
+ class X
34
+ def hello
35
+ blip
36
+ end
37
+ end
38
+
39
+ class Y
40
+ def hello
41
+ blip
42
+ end
43
+ end
44
+ }
45
+ it "should have classs x and y" do
46
+ classs_x_y.should have_classes :x, :y
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'method matcher' do
4
+ context "content without method" do
5
+ no_method = %q{
6
+ class X
7
+ hello
8
+ hi
9
+ end}
10
+
11
+ it "should not have method hello" do
12
+ no_method.should_not have_methods :hello, :hi do |content|
13
+ content.should_not be_empty
14
+ end
15
+ end
16
+ end
17
+
18
+ context "content with method hello" do
19
+ with_method = %q{
20
+ def hello
21
+ blip
22
+ end
23
+ }
24
+ it "should have method hello" do
25
+ with_method.should have_methods :hello
26
+ with_method.should_not have_methods :hi
27
+ with_method.should_not have_methods :hello, :hi
28
+ end
29
+ end
30
+
31
+ context "content with method hello" do
32
+ with_method = %q{
33
+ def hello
34
+ blip
35
+ end
36
+
37
+ def hi
38
+ blip
39
+ end
40
+ }
41
+ it "should have method hello" do
42
+ with_method.should have_methods :hello, :hi
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'modules matcher' do
4
+ context "no module" do
5
+ no_module = %q{
6
+ class X
7
+ hello
8
+ hi
9
+ end
10
+ }
11
+
12
+ it "should not have module X" do
13
+ no_module.should_not have_modules :x
14
+ end
15
+ end
16
+
17
+ context "content with module X" do
18
+ module_x = %q{
19
+ module X
20
+ def hello
21
+ blip
22
+ end
23
+ end
24
+ }
25
+ it "should have module x" do
26
+ module_x.should have_modules :x
27
+ module_x.should_not have_modules :x, :y
28
+ end
29
+ end
30
+
31
+ context "content with module X and Y" do
32
+ modules_x_y = %q{
33
+ module X
34
+ def hello
35
+ blip
36
+ end
37
+ end
38
+
39
+ module Y
40
+ def hello
41
+ blip
42
+ end
43
+ end
44
+ }
45
+ it "should have modules x and y" do
46
+ modules_x_y.should have_modules :x, :y
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
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-09-16 00:00:00 +02:00
17
+ date: 2010-09-18 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -50,9 +50,24 @@ dependencies:
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
- name: activesupport
53
+ name: sugar-high
54
54
  prerelease: false
55
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ - 2
63
+ - 10
64
+ version: 0.2.10
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: activesupport
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
56
71
  none: false
57
72
  requirements:
58
73
  - - ~>
@@ -63,7 +78,7 @@ dependencies:
63
78
  - 0
64
79
  version: 3.0.0
65
80
  type: :runtime
66
- version_requirements: *id003
81
+ version_requirements: *id004
67
82
  description: Code file RSpec 2 matchers that make it easy to spec Ruby code files, fx updated or generated by a Thor generator
68
83
  email: kmandrup@gmail.com
69
84
  executables: []
@@ -99,6 +114,8 @@ files:
99
114
  - lib/code_spec/matchers/include_module.rb
100
115
  - lib/code_spec/matchers/inherit_from.rb
101
116
  - lib/code_spec/matchers/match_lines.rb
117
+ - lib/code_spec/matchers/multi/have_classes_modules.rb
118
+ - lib/code_spec/matchers/multi/have_methods.rb
102
119
  - spec/code-spec/fixtures/logfile.log
103
120
  - spec/code-spec/matchers/class_self_spec.rb
104
121
  - spec/code-spec/matchers/have_block_spec.rb
@@ -113,6 +130,9 @@ files:
113
130
  - spec/code-spec/matchers/include_module_spec.rb
114
131
  - spec/code-spec/matchers/inherit_from_spec.rb
115
132
  - spec/code-spec/matchers/match_content_spec.rb
133
+ - spec/code-spec/matchers/multi/have_classes_spec.rb
134
+ - spec/code-spec/matchers/multi/have_methods_spec.rb
135
+ - spec/code-spec/matchers/multi/have_modules_spec.rb
116
136
  - spec/spec_helper.rb
117
137
  has_rdoc: true
118
138
  homepage: http://github.com/kristianmandrup/code-spec
@@ -160,4 +180,7 @@ test_files:
160
180
  - spec/code-spec/matchers/include_module_spec.rb
161
181
  - spec/code-spec/matchers/inherit_from_spec.rb
162
182
  - spec/code-spec/matchers/match_content_spec.rb
183
+ - spec/code-spec/matchers/multi/have_classes_spec.rb
184
+ - spec/code-spec/matchers/multi/have_methods_spec.rb
185
+ - spec/code-spec/matchers/multi/have_modules_spec.rb
163
186
  - spec/spec_helper.rb