code-spec 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/code-spec.gemspec +112 -0
- data/lib/code-spec.rb +5 -0
- data/lib/code_spec/content_helpers.rb +18 -0
- data/lib/code_spec/core_ext.rb +5 -0
- data/lib/code_spec/erb/base.rb +4 -0
- data/lib/code_spec/erb/code-stripper.rb +31 -0
- data/lib/code_spec/erb/matchers/formtastic/have_formtastic.rb +62 -0
- data/lib/code_spec/erb/matchers/rails_view/have_form.rb +97 -0
- data/lib/code_spec/erb/matchers/simpleform/have_simpleform.rb +47 -0
- data/lib/code_spec/matchers/content_matcher.rb +1 -1
- data/lib/code_spec/matchers/have_block.rb +34 -1
- data/lib/code_spec/matchers/have_call.rb +23 -7
- data/lib/code_spec/matchers/have_comment.rb +0 -7
- data/lib/code_spec/matchers/have_content.rb +28 -0
- data/lib/code_spec/matchers/match_lines.rb +41 -0
- data/spec/code-spec/erb/code-stripper_spec.rb +15 -0
- data/spec/code-spec/erb/matchers/formtastic/have_formtastic_spec.rb +0 -0
- data/spec/code-spec/erb/matchers/rails_view/have_form_spec.rb +0 -0
- data/spec/code-spec/fixtures/logfile.log +5 -0
- data/spec/code-spec/fixtures/view-file.erb +14 -0
- data/spec/code-spec/matchers/have_block_spec.rb +21 -5
- data/spec/code-spec/matchers/match_content_spec.rb +19 -0
- data/spec/spec_helper.rb +3 -0
- metadata +23 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/code-spec.gemspec
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{code-spec}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = %q{2010-08-17}
|
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
|
+
s.email = %q{kmandrup@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
".rspec",
|
23
|
+
"LICENSE",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"code-spec.gemspec",
|
28
|
+
"lib/code-spec.rb",
|
29
|
+
"lib/code_spec/content_helpers.rb",
|
30
|
+
"lib/code_spec/core_ext.rb",
|
31
|
+
"lib/code_spec/erb/base.rb",
|
32
|
+
"lib/code_spec/erb/code-stripper.rb",
|
33
|
+
"lib/code_spec/erb/matchers/formtastic/have_formtastic.rb",
|
34
|
+
"lib/code_spec/erb/matchers/rails_view/have_form.rb",
|
35
|
+
"lib/code_spec/erb/matchers/simpleform/have_simpleform.rb",
|
36
|
+
"lib/code_spec/matchers/content_matcher.rb",
|
37
|
+
"lib/code_spec/matchers/have_block.rb",
|
38
|
+
"lib/code_spec/matchers/have_call.rb",
|
39
|
+
"lib/code_spec/matchers/have_calls.rb",
|
40
|
+
"lib/code_spec/matchers/have_class_self.rb",
|
41
|
+
"lib/code_spec/matchers/have_comment.rb",
|
42
|
+
"lib/code_spec/matchers/have_content.rb",
|
43
|
+
"lib/code_spec/matchers/have_method.rb",
|
44
|
+
"lib/code_spec/matchers/have_module.rb",
|
45
|
+
"lib/code_spec/matchers/have_region.rb",
|
46
|
+
"lib/code_spec/matchers/have_subclass.rb",
|
47
|
+
"lib/code_spec/matchers/include_module.rb",
|
48
|
+
"lib/code_spec/matchers/inherit_from.rb",
|
49
|
+
"lib/code_spec/matchers/match_lines.rb",
|
50
|
+
"spec/code-spec/erb/code-stripper_spec.rb",
|
51
|
+
"spec/code-spec/erb/matchers/formtastic/have_formtastic_spec.rb",
|
52
|
+
"spec/code-spec/erb/matchers/rails_view/have_form_spec.rb",
|
53
|
+
"spec/code-spec/fixtures/logfile.log",
|
54
|
+
"spec/code-spec/fixtures/view-file.erb",
|
55
|
+
"spec/code-spec/matchers/class_self_spec.rb",
|
56
|
+
"spec/code-spec/matchers/have_block_spec.rb",
|
57
|
+
"spec/code-spec/matchers/have_call_spec.rb",
|
58
|
+
"spec/code-spec/matchers/have_calls_spec.rb",
|
59
|
+
"spec/code-spec/matchers/have_class_spec.rb",
|
60
|
+
"spec/code-spec/matchers/have_method_spec.rb",
|
61
|
+
"spec/code-spec/matchers/have_module_spec.rb",
|
62
|
+
"spec/code-spec/matchers/have_region_spec.rb",
|
63
|
+
"spec/code-spec/matchers/have_subclass_spec.rb",
|
64
|
+
"spec/code-spec/matchers/include_module_spec.rb",
|
65
|
+
"spec/code-spec/matchers/inherit_from_spec.rb",
|
66
|
+
"spec/code-spec/matchers/match_content_spec.rb",
|
67
|
+
"spec/spec_helper.rb"
|
68
|
+
]
|
69
|
+
s.homepage = %q{http://github.com/kristianmandrup/code-spec}
|
70
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
71
|
+
s.require_paths = ["lib"]
|
72
|
+
s.rubygems_version = %q{1.3.7}
|
73
|
+
s.summary = %q{Code file RSpec 2 matchers}
|
74
|
+
s.test_files = [
|
75
|
+
"spec/code-spec/erb/code-stripper_spec.rb",
|
76
|
+
"spec/code-spec/erb/matchers/formtastic/have_formtastic_spec.rb",
|
77
|
+
"spec/code-spec/erb/matchers/rails_view/have_form_spec.rb",
|
78
|
+
"spec/code-spec/matchers/class_self_spec.rb",
|
79
|
+
"spec/code-spec/matchers/have_block_spec.rb",
|
80
|
+
"spec/code-spec/matchers/have_call_spec.rb",
|
81
|
+
"spec/code-spec/matchers/have_calls_spec.rb",
|
82
|
+
"spec/code-spec/matchers/have_class_spec.rb",
|
83
|
+
"spec/code-spec/matchers/have_method_spec.rb",
|
84
|
+
"spec/code-spec/matchers/have_module_spec.rb",
|
85
|
+
"spec/code-spec/matchers/have_region_spec.rb",
|
86
|
+
"spec/code-spec/matchers/have_subclass_spec.rb",
|
87
|
+
"spec/code-spec/matchers/include_module_spec.rb",
|
88
|
+
"spec/code-spec/matchers/inherit_from_spec.rb",
|
89
|
+
"spec/code-spec/matchers/match_content_spec.rb",
|
90
|
+
"spec/spec_helper.rb"
|
91
|
+
]
|
92
|
+
|
93
|
+
if s.respond_to? :specification_version then
|
94
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
95
|
+
s.specification_version = 3
|
96
|
+
|
97
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
98
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
99
|
+
s.add_runtime_dependency(%q<require_all>, [">= 1.1.0"])
|
100
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.rc"])
|
101
|
+
else
|
102
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
103
|
+
s.add_dependency(%q<require_all>, [">= 1.1.0"])
|
104
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0.rc"])
|
105
|
+
end
|
106
|
+
else
|
107
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
108
|
+
s.add_dependency(%q<require_all>, [">= 1.1.0"])
|
109
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0.rc"])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
data/lib/code-spec.rb
CHANGED
@@ -10,6 +10,11 @@ end
|
|
10
10
|
require 'code_spec/matchers/content_matcher'
|
11
11
|
require_all File.dirname(__FILE__) + '/code_spec/matchers'
|
12
12
|
|
13
|
+
require_all File.dirname(__FILE__) + '/code_spec/erb'
|
14
|
+
|
15
|
+
require 'code_spec/content_helpers'
|
16
|
+
require 'code_spec/core_ext'
|
17
|
+
|
13
18
|
RSpec.configure do |config|
|
14
19
|
config.include(RSpec::RubyContentMatchers)
|
15
20
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RSpec::RubyContent
|
2
|
+
module Helpers
|
3
|
+
def check_matchings matchings
|
4
|
+
matchings.each do |matching|
|
5
|
+
self.should match /#{Regexp.escape(matching)}/
|
6
|
+
end
|
7
|
+
end
|
8
|
+
alias_method :matchings, :check_matchings
|
9
|
+
|
10
|
+
|
11
|
+
def check_methods methods, type=nil
|
12
|
+
methods.each do |method_name|
|
13
|
+
self.should have_method(method_name, type)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
alias_method :methods, :check_methods
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Erb
|
2
|
+
module Code
|
3
|
+
class << self
|
4
|
+
attr_accessor :debug
|
5
|
+
|
6
|
+
def debug?
|
7
|
+
debug
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.get_code code
|
12
|
+
puts code if debug?
|
13
|
+
erb = code.scan(/<%-?=?\s*(.*?)\s*-?%>/).flatten.join "\n"
|
14
|
+
puts erb if debug?
|
15
|
+
erb
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class String
|
21
|
+
def erb_code code
|
22
|
+
Erb::Code.get_code code
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class File
|
27
|
+
def erb_code
|
28
|
+
Erb::Code.get_code File.read(self)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Erb::Formtastic
|
2
|
+
module ContentMatchers
|
3
|
+
def have_semantic_form_for name
|
4
|
+
have_form_call :semantic_form_for, :args => name
|
5
|
+
end
|
6
|
+
|
7
|
+
def have_inputs name
|
8
|
+
have_form_call :inputs, :args => ":name => #{name}"
|
9
|
+
end
|
10
|
+
alias_method :have_input_field_set, :have_inputs
|
11
|
+
|
12
|
+
def have_buttons name
|
13
|
+
have_form_call :buttons
|
14
|
+
end
|
15
|
+
alias_method :have_button_field_set, :have_buttons
|
16
|
+
|
17
|
+
def have_label name
|
18
|
+
have_form_call :label, :args => ":#{name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.inputs_list
|
22
|
+
[ :radio, :date, :text, :select, :checkboxes, :time_zone, :password, :date, :datetime, :time, :boolean, :string, :numeric, :country, :hidden ]
|
23
|
+
end
|
24
|
+
|
25
|
+
inputs_list.each do |name|
|
26
|
+
class_eval %{
|
27
|
+
def have_#{name} name
|
28
|
+
have_form_call :input, :args => ":\#{name}, :as => :#{name}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def have_required_#{name} name
|
32
|
+
have_form_call :input, :args => ":\#{name}, :required => true, :as => :#{name}"
|
33
|
+
end
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def have_input name
|
38
|
+
have_form_call :input, :args => ":#{name}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def have_required_input name
|
42
|
+
have_form_call :input, :args => ":#{name}, :required => true"
|
43
|
+
end
|
44
|
+
|
45
|
+
def have_errors_for name
|
46
|
+
have_form_call :input, :args => ":#{name}"
|
47
|
+
end
|
48
|
+
alias_method :have_inline_errors_for, :have_errors_for
|
49
|
+
|
50
|
+
def have_semantic_errors
|
51
|
+
have_form_call :semantic_errors
|
52
|
+
end
|
53
|
+
|
54
|
+
def have_semantic_fields_for
|
55
|
+
have_form_call :semantic_fields_for
|
56
|
+
end
|
57
|
+
|
58
|
+
def have_commit_button
|
59
|
+
have_form_call :commit_button
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Erb::RailsForm
|
2
|
+
module Base
|
3
|
+
module ContentMatchers
|
4
|
+
def have_form_block name
|
5
|
+
have_block :form_for, :args => name
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.form_helpers
|
9
|
+
[:check_box, :file_field, :hidden_field, :label, :password_field, :radio_button, :text_area]
|
10
|
+
end
|
11
|
+
|
12
|
+
form_helpers.each do |name|
|
13
|
+
class_eval %{
|
14
|
+
def have_#{name} obj_name, args=nil
|
15
|
+
args = args ? ":name => \#{obj_name}, \#{args}" : ":name => \#{obj_name}"
|
16
|
+
have_form_call :#{name}, :args => args
|
17
|
+
end
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Tags
|
24
|
+
|
25
|
+
def have_field_set_tag legend
|
26
|
+
have_form_call :field_set_tag, :args => "'#{legend}'"
|
27
|
+
end
|
28
|
+
|
29
|
+
def have_form_tag url
|
30
|
+
have_form_call :form_tag, :args => "'#{url}'"
|
31
|
+
end
|
32
|
+
|
33
|
+
def have_password_field_tag name = "password"
|
34
|
+
have_form_call :password_field_tag, :args => "'#{name}'"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.tags_list
|
38
|
+
[ :check_box_tag, :file_field_tag, :text_field_tag, :hidden_field_tag, :image_submit_tag,
|
39
|
+
:radio_button_tag, :select_tag, :label_tag, :submit_tag, :text_area_tag ]
|
40
|
+
end
|
41
|
+
|
42
|
+
tags_list.each do |name|
|
43
|
+
class_eval %{
|
44
|
+
def have_#{name} name
|
45
|
+
have_form_call :#{name}, :args => "'\#{name}'"
|
46
|
+
end
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
module Options
|
53
|
+
def self.options_methods
|
54
|
+
[ :grouped_collection_select, :option_groups_from_collection_for_select, :option_groups_from_collection_for_select,
|
55
|
+
:options_from_collection_for_select, :time_zone_options_for_select ]
|
56
|
+
|
57
|
+
options_methods.each do |name|
|
58
|
+
class_eval %{
|
59
|
+
def have_#{name} name
|
60
|
+
have_form_call :#{name}
|
61
|
+
end
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.name_options_methods
|
66
|
+
[ :collection_select, :grouped_collection_select, :select, :time_zone_select ]
|
67
|
+
end
|
68
|
+
|
69
|
+
name_options_methods.each do |name|
|
70
|
+
class_eval %{
|
71
|
+
def have_#{name} name
|
72
|
+
have_form_call :collection_select, :args => ":#{name}"
|
73
|
+
end
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
module Links
|
79
|
+
def self.link_methods
|
80
|
+
[ :button_to, :link_to, :mail_to ]
|
81
|
+
end
|
82
|
+
|
83
|
+
link_methods.each do |name|
|
84
|
+
class_eval %{
|
85
|
+
def have_#{name} args
|
86
|
+
have_form_call :collection_select, :args => args
|
87
|
+
end
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def have_submit_button
|
92
|
+
HaveDotCall.new(:submit)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Erb::SimpleForm
|
2
|
+
module ContentMatchers
|
3
|
+
def have_simple_form_block name
|
4
|
+
have_block :simple_form_for, :args => name
|
5
|
+
end
|
6
|
+
|
7
|
+
def have_input name
|
8
|
+
have_form_call :input, :args => ":#{name}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def have_button name
|
12
|
+
have_form_call :button, :args => ":#{name}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.standard_inputs
|
16
|
+
[ :username, :email, :website, :age, :password, :remember_me]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.association_types
|
20
|
+
[ :radio, :check_boxes]
|
21
|
+
end
|
22
|
+
|
23
|
+
def have_association name
|
24
|
+
have_form_call :association, :args => ":#{name}"
|
25
|
+
end
|
26
|
+
|
27
|
+
association_types.each do |name|
|
28
|
+
class_eval %{
|
29
|
+
def have_#{name.to_s.pluralize} name
|
30
|
+
have_form_call :association, :args => ":\#{name}, :as => :#{name}"
|
31
|
+
end
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
standard_inputs.each do |name|
|
36
|
+
class_eval %{
|
37
|
+
def have_#{name}
|
38
|
+
have_input :#{name}
|
39
|
+
end
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def have_commit_button
|
44
|
+
have_form_call :commit_button
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RSpec::RubyContentMatchers
|
2
2
|
class HaveBlock < RSpec::RubyContentMatcher
|
3
|
-
attr_reader :name, :args, :block_args, :do_option, :end_option
|
3
|
+
attr_reader :name, :args, :block_args, :do_option, :end_option, :block_arguments
|
4
4
|
|
5
5
|
def initialize(name, options={})
|
6
6
|
super options[:end] || name
|
@@ -9,6 +9,39 @@ module RSpec::RubyContentMatchers
|
|
9
9
|
@do_option = options[:do].nil? ? true : options[:do]
|
10
10
|
@block_args = options[:block_args]
|
11
11
|
end
|
12
|
+
|
13
|
+
module BlockArgs
|
14
|
+
attr_accessor :block_args, :form
|
15
|
+
|
16
|
+
def form
|
17
|
+
block_args[0]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def matches? content, &block
|
22
|
+
@content = content
|
23
|
+
blockargs = content.scan(/do\s+\|(.*?)\|/).flatten[0]
|
24
|
+
@block_arguments = blockargs.split ',' if blockargs
|
25
|
+
|
26
|
+
match = is_match? content
|
27
|
+
content_to_yield = if indexes
|
28
|
+
content_matches[indexes.first] || content_matches[indexes.last]
|
29
|
+
else
|
30
|
+
content_matches[index]
|
31
|
+
end
|
32
|
+
handle_result(content_to_yield, match, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def handle_result content, match, &block
|
36
|
+
if block && match && content
|
37
|
+
ruby_content = content.strip
|
38
|
+
ruby_content.extend(BlockArgs)
|
39
|
+
ruby_content.block_args = block_arguments
|
40
|
+
yield ruby_content
|
41
|
+
end
|
42
|
+
match
|
43
|
+
end
|
44
|
+
|
12
45
|
|
13
46
|
def failure_message
|
14
47
|
super
|
@@ -7,18 +7,23 @@
|
|
7
7
|
#
|
8
8
|
module RSpec::RubyContentMatchers
|
9
9
|
class HaveCall < RSpec::RubyContentMatcher
|
10
|
-
attr_reader :method, :args, :dot
|
10
|
+
attr_reader :method, :args, :dot, :content
|
11
11
|
|
12
12
|
def initialize(method, options = {})
|
13
13
|
@method = method.to_s
|
14
|
-
@args =
|
14
|
+
@args = case options
|
15
|
+
when Hash
|
16
|
+
options[:args]
|
17
|
+
else
|
18
|
+
options
|
19
|
+
end
|
15
20
|
@dot = options[:dot]
|
16
21
|
end
|
17
22
|
|
18
23
|
def matches?(content)
|
19
|
-
@content = content
|
24
|
+
@content = content
|
20
25
|
has_def = (content =~ /def(.*)#{method}/)
|
21
|
-
expr = if has_def
|
26
|
+
expr = if has_def || dot == :form
|
22
27
|
/#{dot_expr}#{method}#{args_expr}/m
|
23
28
|
else
|
24
29
|
/#{dot_expr}?#{method}#{args_expr}/m
|
@@ -46,8 +51,14 @@ module RSpec::RubyContentMatchers
|
|
46
51
|
end
|
47
52
|
|
48
53
|
def dot_expr
|
49
|
-
|
50
|
-
|
54
|
+
case dot
|
55
|
+
when String
|
56
|
+
Regexp.escape(dot)
|
57
|
+
when Symbol
|
58
|
+
"#{content.form}\." if content.respond_to? :form
|
59
|
+
else
|
60
|
+
dot ? "#{not_def}\." : not_def
|
61
|
+
end
|
51
62
|
end
|
52
63
|
|
53
64
|
end
|
@@ -57,6 +68,11 @@ module RSpec::RubyContentMatchers
|
|
57
68
|
end
|
58
69
|
|
59
70
|
def have_dot_call(method, options = {})
|
60
|
-
|
71
|
+
have_call method, options.merge(:dot => true)
|
72
|
+
end
|
73
|
+
|
74
|
+
def have_form_call(method, options = {})
|
75
|
+
have_call method, options.merge(:dot => :form)
|
61
76
|
end
|
77
|
+
|
62
78
|
end
|
@@ -1,10 +1,3 @@
|
|
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
1
|
module RSpec::RubyContentMatchers
|
9
2
|
class HaveComment < RSpec::RubyContentMatcher
|
10
3
|
attr_accessor :comment
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RSpec::RubyContentMatchers
|
2
|
+
class HaveContent
|
3
|
+
attr_accessor :file_path
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(file_path, &block)
|
9
|
+
self.file_path = file_path
|
10
|
+
return nil if File.blank? file_path
|
11
|
+
file = File.new(file_path)
|
12
|
+
yield file.read if block
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def failure_message
|
17
|
+
"Expected the file #{file_path} to have content"
|
18
|
+
end
|
19
|
+
|
20
|
+
def negative_failure_message
|
21
|
+
"Did not expect the file #{file_path} to have content"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def have_content
|
26
|
+
HaveContent.new
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RSpec::RubyContentMatchers
|
2
|
+
class MatchLines
|
3
|
+
attr_accessor :lines, :separator
|
4
|
+
|
5
|
+
def initialize *lines
|
6
|
+
lines = lines.flatten
|
7
|
+
last_arg = lines.last
|
8
|
+
separator = case last_arg
|
9
|
+
when Hash
|
10
|
+
self.lines = lines[0..-2].flatten
|
11
|
+
last_arg[:separator]
|
12
|
+
else
|
13
|
+
self.lines = lines
|
14
|
+
"\n"
|
15
|
+
end
|
16
|
+
self.separator = separator
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches?(content, &block)
|
20
|
+
lines.each do |txt|
|
21
|
+
txt.split(separator).each do |line|
|
22
|
+
return nil if !(content =~ /#{Regexp.escape(line)}/)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def failure_message
|
29
|
+
"Expected the string to match the lines"
|
30
|
+
end
|
31
|
+
|
32
|
+
def negative_failure_message
|
33
|
+
super
|
34
|
+
"Did not expect string to match the lines"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def match_lines *lines
|
39
|
+
MatchLines.new lines
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Erb
|
4
|
+
module Code
|
5
|
+
describe '#erb_code' do
|
6
|
+
context "valid ERB file" do
|
7
|
+
it "should get only the ERB code from a valid ERB file" do
|
8
|
+
debug = false # true
|
9
|
+
erb_file = File.join(fixtures_dir, 'view-file.erb')
|
10
|
+
File.new(erb_file).erb_code.should match_lines %{for @item in @items\nhello :you\nhello :me}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
File without changes
|
@@ -10,13 +10,13 @@ describe 'block matcher' do
|
|
10
10
|
not_class_self.should_not have_block :hello
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
context "content with block: hello do" do
|
15
15
|
content = %q{
|
16
16
|
hello do
|
17
17
|
blip
|
18
18
|
end # do}
|
19
|
-
|
19
|
+
|
20
20
|
it "should have block" do
|
21
21
|
content.should have_block :hello
|
22
22
|
end
|
@@ -27,12 +27,12 @@ describe 'block matcher' do
|
|
27
27
|
hello :angel do
|
28
28
|
blip
|
29
29
|
end # do}
|
30
|
-
|
30
|
+
|
31
31
|
it "should have block" do
|
32
32
|
content.should have_block :hello, :args => ':angel'
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
context "content with block: hello :angel do |x,y|" do
|
37
37
|
content = %q{
|
38
38
|
hello :angel do |x,y|
|
@@ -40,9 +40,25 @@ describe 'block matcher' do
|
|
40
40
|
end # do}
|
41
41
|
|
42
42
|
it "should have block" do
|
43
|
-
content.should have_block :hello, :args => ':angel', :block_args => 'x,y'
|
43
|
+
content.should have_block :hello, :args => ':angel', :block_args => 'x,y' do |block|
|
44
|
+
block.form.should_not be_nil
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|
48
|
+
|
49
|
+
context "content with block: hello :angel do |x,y|" do
|
50
|
+
content = %q{
|
51
|
+
form_for :person do |my_form|
|
52
|
+
my_form.input :name
|
53
|
+
end # do}
|
54
|
+
|
55
|
+
it "should have my_form input called :name" do
|
56
|
+
content.should have_block :form_for, :args => ':person' do |form_block|
|
57
|
+
form_block.should have_form_call :input, :args => ':name'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
46
62
|
end
|
47
63
|
|
48
64
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'inherit matcher' do
|
4
|
+
context "content with class that inherits from Greeting" do
|
5
|
+
logfile = File.join(fixtures_dir, 'logfile.log')
|
6
|
+
|
7
|
+
it "content should match some lines" do
|
8
|
+
logfile.should have_content do |content|
|
9
|
+
content.should match_lines %{By default we are in into log mode\nThis is debugging mode!\nMore info... but still in debugging mode}
|
10
|
+
content.should match_lines %{By default we are in into log mode:::This is debugging mode!:::More info... but still in debugging mode}, :separator => ':::'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.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-
|
17
|
+
date: 2010-08-17 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -82,19 +82,34 @@ files:
|
|
82
82
|
- README.markdown
|
83
83
|
- Rakefile
|
84
84
|
- VERSION
|
85
|
+
- code-spec.gemspec
|
85
86
|
- lib/code-spec.rb
|
87
|
+
- lib/code_spec/content_helpers.rb
|
88
|
+
- lib/code_spec/core_ext.rb
|
89
|
+
- lib/code_spec/erb/base.rb
|
90
|
+
- lib/code_spec/erb/code-stripper.rb
|
91
|
+
- lib/code_spec/erb/matchers/formtastic/have_formtastic.rb
|
92
|
+
- lib/code_spec/erb/matchers/rails_view/have_form.rb
|
93
|
+
- lib/code_spec/erb/matchers/simpleform/have_simpleform.rb
|
86
94
|
- lib/code_spec/matchers/content_matcher.rb
|
87
95
|
- lib/code_spec/matchers/have_block.rb
|
88
96
|
- lib/code_spec/matchers/have_call.rb
|
89
97
|
- lib/code_spec/matchers/have_calls.rb
|
90
98
|
- lib/code_spec/matchers/have_class_self.rb
|
91
99
|
- lib/code_spec/matchers/have_comment.rb
|
100
|
+
- lib/code_spec/matchers/have_content.rb
|
92
101
|
- lib/code_spec/matchers/have_method.rb
|
93
102
|
- lib/code_spec/matchers/have_module.rb
|
94
103
|
- lib/code_spec/matchers/have_region.rb
|
95
104
|
- lib/code_spec/matchers/have_subclass.rb
|
96
105
|
- lib/code_spec/matchers/include_module.rb
|
97
106
|
- lib/code_spec/matchers/inherit_from.rb
|
107
|
+
- lib/code_spec/matchers/match_lines.rb
|
108
|
+
- spec/code-spec/erb/code-stripper_spec.rb
|
109
|
+
- spec/code-spec/erb/matchers/formtastic/have_formtastic_spec.rb
|
110
|
+
- spec/code-spec/erb/matchers/rails_view/have_form_spec.rb
|
111
|
+
- spec/code-spec/fixtures/logfile.log
|
112
|
+
- spec/code-spec/fixtures/view-file.erb
|
98
113
|
- spec/code-spec/matchers/class_self_spec.rb
|
99
114
|
- spec/code-spec/matchers/have_block_spec.rb
|
100
115
|
- spec/code-spec/matchers/have_call_spec.rb
|
@@ -106,6 +121,7 @@ files:
|
|
106
121
|
- spec/code-spec/matchers/have_subclass_spec.rb
|
107
122
|
- spec/code-spec/matchers/include_module_spec.rb
|
108
123
|
- spec/code-spec/matchers/inherit_from_spec.rb
|
124
|
+
- spec/code-spec/matchers/match_content_spec.rb
|
109
125
|
- spec/spec_helper.rb
|
110
126
|
has_rdoc: true
|
111
127
|
homepage: http://github.com/kristianmandrup/code-spec
|
@@ -140,6 +156,9 @@ signing_key:
|
|
140
156
|
specification_version: 3
|
141
157
|
summary: Code file RSpec 2 matchers
|
142
158
|
test_files:
|
159
|
+
- spec/code-spec/erb/code-stripper_spec.rb
|
160
|
+
- spec/code-spec/erb/matchers/formtastic/have_formtastic_spec.rb
|
161
|
+
- spec/code-spec/erb/matchers/rails_view/have_form_spec.rb
|
143
162
|
- spec/code-spec/matchers/class_self_spec.rb
|
144
163
|
- spec/code-spec/matchers/have_block_spec.rb
|
145
164
|
- spec/code-spec/matchers/have_call_spec.rb
|
@@ -151,4 +170,5 @@ test_files:
|
|
151
170
|
- spec/code-spec/matchers/have_subclass_spec.rb
|
152
171
|
- spec/code-spec/matchers/include_module_spec.rb
|
153
172
|
- spec/code-spec/matchers/inherit_from_spec.rb
|
173
|
+
- spec/code-spec/matchers/match_content_spec.rb
|
154
174
|
- spec/spec_helper.rb
|