code-spec 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,12 +1,17 @@
1
1
  # Code spec
2
2
 
3
3
  RSpec 2 matchers to facilitate making specs regarding Ruby code files, f.ex as generated or modified/mutated by a code generator.
4
+ Also includes matchers to help spec ERB code that include either:
5
+
6
+ * Standard rails forms
7
+ * Formtastic
8
+ * Simpleform
4
9
 
5
10
  ## Install
6
11
 
7
12
  gem install code-spec
8
13
 
9
- ## Usage
14
+ ## Usage: Basic code matchers
10
15
 
11
16
  See specs for examples on how to use it.
12
17
 
@@ -28,6 +33,32 @@ Example: Nested DSL
28
33
  end
29
34
  </pre>
30
35
 
36
+ ## Usage: Form matchers
37
+
38
+ *with_form_helper* is used to specify which form helper to use. It can be either:
39
+
40
+ * :formtastic
41
+ * :simpleform
42
+ * :railsform
43
+
44
+ <pre>
45
+ describe 'Formtastic form matcher' do
46
+ with_form_helper :formtastic
47
+
48
+ context "Formtastic example 1 view file" do
49
+ let(:form_file) { File.join erb_fixtures_dir, 'formtastic-ex1.erb' }
50
+
51
+ it "content should match form expectations" do
52
+ form_file.should have_content do |content|
53
+ content.erb_code.should have_semantic_form_for '@article' do |form|
54
+ form.should have_inputs "Basic"
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ </pre>
61
+
31
62
  ## Note on Patches/Pull Requests
32
63
 
33
64
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
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.1.3"
8
+ s.version = "0.2.0"
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-17}
12
+ s.date = %q{2010-08-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 = [
@@ -28,14 +28,6 @@ Gem::Specification.new do |s|
28
28
  "lib/code-spec.rb",
29
29
  "lib/code_spec/content_helpers.rb",
30
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/rails_view/helpers/links.rb",
36
- "lib/code_spec/erb/matchers/rails_view/helpers/options.rb",
37
- "lib/code_spec/erb/matchers/rails_view/helpers/tags.rb",
38
- "lib/code_spec/erb/matchers/simpleform/have_simpleform.rb",
39
31
  "lib/code_spec/matchers/content_matcher.rb",
40
32
  "lib/code_spec/matchers/have_block.rb",
41
33
  "lib/code_spec/matchers/have_call.rb",
@@ -50,14 +42,6 @@ Gem::Specification.new do |s|
50
42
  "lib/code_spec/matchers/include_module.rb",
51
43
  "lib/code_spec/matchers/inherit_from.rb",
52
44
  "lib/code_spec/matchers/match_lines.rb",
53
- "spec/code-spec/erb/code-stripper_spec.rb",
54
- "spec/code-spec/erb/matchers/formtastic/have_formtastic_spec.rb",
55
- "spec/code-spec/erb/matchers/rails_view/have_form_spec.rb",
56
- "spec/code-spec/erb/matchers/simpleform/have_simpleform_spec.rb",
57
- "spec/code-spec/fixtures/erb/formtastic-ex1.erb",
58
- "spec/code-spec/fixtures/erb/railsform-ex1.erb",
59
- "spec/code-spec/fixtures/erb/simpleform-ex1.erb",
60
- "spec/code-spec/fixtures/erb/view-file.erb",
61
45
  "spec/code-spec/fixtures/logfile.log",
62
46
  "spec/code-spec/matchers/class_self_spec.rb",
63
47
  "spec/code-spec/matchers/have_block_spec.rb",
@@ -79,11 +63,7 @@ Gem::Specification.new do |s|
79
63
  s.rubygems_version = %q{1.3.7}
80
64
  s.summary = %q{Code file RSpec 2 matchers}
81
65
  s.test_files = [
82
- "spec/code-spec/erb/code-stripper_spec.rb",
83
- "spec/code-spec/erb/matchers/formtastic/have_formtastic_spec.rb",
84
- "spec/code-spec/erb/matchers/rails_view/have_form_spec.rb",
85
- "spec/code-spec/erb/matchers/simpleform/have_simpleform_spec.rb",
86
- "spec/code-spec/matchers/class_self_spec.rb",
66
+ "spec/code-spec/matchers/class_self_spec.rb",
87
67
  "spec/code-spec/matchers/have_block_spec.rb",
88
68
  "spec/code-spec/matchers/have_call_spec.rb",
89
69
  "spec/code-spec/matchers/have_calls_spec.rb",
data/lib/code-spec.rb CHANGED
@@ -10,8 +10,6 @@ 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
13
  require 'code_spec/content_helpers'
16
14
  require 'code_spec/core_ext'
17
15
 
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,3 @@ require 'code-spec'
5
5
  def fixtures_dir
6
6
  File.expand_path(File.dirname(__FILE__) + '/code-spec/fixtures')
7
7
  end
8
-
9
- def erb_fixtures_dir
10
- File.join(fixtures_dir, 'erb')
11
- end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 3
9
- version: 0.1.3
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
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 00:00:00 +02:00
17
+ date: 2010-08-18 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -86,14 +86,6 @@ files:
86
86
  - lib/code-spec.rb
87
87
  - lib/code_spec/content_helpers.rb
88
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/rails_view/helpers/links.rb
94
- - lib/code_spec/erb/matchers/rails_view/helpers/options.rb
95
- - lib/code_spec/erb/matchers/rails_view/helpers/tags.rb
96
- - lib/code_spec/erb/matchers/simpleform/have_simpleform.rb
97
89
  - lib/code_spec/matchers/content_matcher.rb
98
90
  - lib/code_spec/matchers/have_block.rb
99
91
  - lib/code_spec/matchers/have_call.rb
@@ -108,14 +100,6 @@ files:
108
100
  - lib/code_spec/matchers/include_module.rb
109
101
  - lib/code_spec/matchers/inherit_from.rb
110
102
  - lib/code_spec/matchers/match_lines.rb
111
- - spec/code-spec/erb/code-stripper_spec.rb
112
- - spec/code-spec/erb/matchers/formtastic/have_formtastic_spec.rb
113
- - spec/code-spec/erb/matchers/rails_view/have_form_spec.rb
114
- - spec/code-spec/erb/matchers/simpleform/have_simpleform_spec.rb
115
- - spec/code-spec/fixtures/erb/formtastic-ex1.erb
116
- - spec/code-spec/fixtures/erb/railsform-ex1.erb
117
- - spec/code-spec/fixtures/erb/simpleform-ex1.erb
118
- - spec/code-spec/fixtures/erb/view-file.erb
119
103
  - spec/code-spec/fixtures/logfile.log
120
104
  - spec/code-spec/matchers/class_self_spec.rb
121
105
  - spec/code-spec/matchers/have_block_spec.rb
@@ -163,10 +147,6 @@ signing_key:
163
147
  specification_version: 3
164
148
  summary: Code file RSpec 2 matchers
165
149
  test_files:
166
- - spec/code-spec/erb/code-stripper_spec.rb
167
- - spec/code-spec/erb/matchers/formtastic/have_formtastic_spec.rb
168
- - spec/code-spec/erb/matchers/rails_view/have_form_spec.rb
169
- - spec/code-spec/erb/matchers/simpleform/have_simpleform_spec.rb
170
150
  - spec/code-spec/matchers/class_self_spec.rb
171
151
  - spec/code-spec/matchers/have_block_spec.rb
172
152
  - spec/code-spec/matchers/have_call_spec.rb
@@ -1,4 +0,0 @@
1
- module Erb
2
- module Formtastic
3
- end
4
- end
@@ -1,31 +0,0 @@
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
22
- Erb::Code.get_code self
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
-
@@ -1,62 +0,0 @@
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
@@ -1,26 +0,0 @@
1
- require_all File.dirname(__FILE__) + '/helpers'
2
-
3
- module Erb::RailsForm
4
- module ContentMatchers
5
- def have_form_for name
6
- have_block :form_for, :args => name
7
- end
8
-
9
- def self.form_helpers
10
- [:check_box, :file_field, :hidden_field, :label, :password_field, :radio_button, :text_area]
11
- end
12
-
13
- form_helpers.each do |name|
14
- class_eval %{
15
- def have_#{name} obj_name, args=nil
16
- args = args ? ":\#{obj_name}, \#{args}" : ":\#{obj_name}"
17
- have_form_call :#{name}, :args => args
18
- end
19
- }
20
- end
21
-
22
- include LinkHelpers
23
- include OptionHelpers
24
- include TagHelpers
25
- end
26
- end
@@ -1,21 +0,0 @@
1
- module Erb::RailsForm
2
- module ContentMatchers
3
- module LinkHelpers
4
- def self.link_methods
5
- [ :button_to, :link_to, :mail_to ]
6
- end
7
-
8
- link_methods.each do |name|
9
- class_eval %{
10
- def have_#{name} args
11
- have_form_call :collection_select, :args => args
12
- end
13
- }
14
- end
15
-
16
- def have_submit_button
17
- HaveDotCall.new(:submit)
18
- end
19
- end
20
- end
21
- end
@@ -1,30 +0,0 @@
1
- module Erb::RailsForm
2
- module ContentMatchers
3
- module OptionHelpers
4
- def self.options_methods
5
- [ :grouped_collection_select, :option_groups_from_collection_for_select, :option_groups_from_collection_for_select,
6
- :options_from_collection_for_select, :time_zone_options_for_select ]
7
- end
8
-
9
- options_methods.each do |name|
10
- class_eval %{
11
- def have_#{name} name
12
- have_form_call :#{name}
13
- end
14
- }
15
- end
16
-
17
- def self.name_options_methods
18
- [ :collection_select, :grouped_collection_select, :select, :time_zone_select ]
19
- end
20
-
21
- name_options_methods.each do |name|
22
- class_eval %{
23
- def have_#{name} name
24
- have_form_call :collection_select, :args => ":#{name}"
25
- end
26
- }
27
- end
28
- end
29
- end
30
- end
@@ -1,30 +0,0 @@
1
- module Erb::RailsForm
2
- module ContentMatchers
3
- module TagHelpers
4
- def have_field_set_tag legend
5
- have_form_call :field_set_tag, :args => "'#{legend}'"
6
- end
7
-
8
- def have_form_tag url
9
- have_form_call :form_tag, :args => "'#{url}'"
10
- end
11
-
12
- def have_password_field_tag name = "password"
13
- have_form_call :password_field_tag, :args => "'#{name}'"
14
- end
15
-
16
- def self.tags_list
17
- [ :check_box_tag, :file_field_tag, :text_field_tag, :hidden_field_tag, :image_submit_tag,
18
- :radio_button_tag, :select_tag, :label_tag, :submit_tag, :text_area_tag ]
19
- end
20
-
21
- tags_list.each do |name|
22
- class_eval %{
23
- def have_#{name} name
24
- have_form_call :#{name}, :args => "'\#{name}'"
25
- end
26
- }
27
- end
28
- end
29
- end
30
- end
@@ -1,47 +0,0 @@
1
- module Erb::SimpleForm
2
- module ContentMatchers
3
- def have_simple_form_for 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,15 +0,0 @@
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(erb_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
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Formtastic form matcher' do
4
- with_form_helper :formtastic
5
-
6
- context "Formtastic example 1 view file" do
7
- form_file = File.join(erb_fixtures_dir, 'formtastic-ex1.erb')
8
- it "content should match form expectations" do
9
- form_file.should have_content do |content|
10
- content.erb_code.should have_semantic_form_for '@article' do |form|
11
- form.should have_inputs "Basic"
12
- end
13
- end
14
- end
15
- end
16
- end
17
-
18
-
19
-
20
-
21
-
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Rails 3 form matcher' do
4
- with_form_helper :rails_form
5
-
6
- context "Rails 3 form example 1 view file" do
7
- form_file = File.join(erb_fixtures_dir, 'railsform-ex1.erb')
8
-
9
- it "content should match form expectations" do
10
- form_file.should have_content do |content|
11
- content.erb_code.should have_form_for '@person' do |form|
12
- form.should have_label :name
13
- end
14
- end
15
- end
16
- end
17
- end
18
-
19
-
20
-
21
-
22
-
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Simpleform form matcher' do
4
- with_form_helper :simpleform
5
-
6
- context "Simpleform example 1 view file" do
7
- form_file = File.join(erb_fixtures_dir, 'simpleform-ex1.erb')
8
-
9
- it "content should match form expectations" do
10
- form_file.should have_content do |content|
11
- content.erb_code.should have_simple_form_for '@user' do |form|
12
- form.should have_username
13
- end
14
- end
15
- end
16
- end
17
- end
18
-
19
-
20
-
21
-
22
-
@@ -1,28 +0,0 @@
1
- <% semantic_form_for @article do |form| %>
2
-
3
- <% form.inputs :name => "Basic" do %>
4
- <%= form.input :title %>
5
- <%= form.input :body %>
6
- <%= form.input :section %>
7
- <%= form.input :publication_state, :as => :radio %>
8
- <%= form.input :category %>
9
- <%= form.input :allow_comments, :label => "Allow commenting on this article" %>
10
- <% end %>
11
-
12
- <% form.inputs :name => "Advanced" do %>
13
- <%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
14
- <%= form.input :extract, :required => false %>
15
- <%= form.input :description, :required => false %>
16
- <%= form.input :url_title, :required => false %>
17
- <% end %>
18
-
19
- <% form.inputs :name => "Author", :for => :author do |author_form| %>
20
- <%= author_form.input :first_name %>
21
- <%= author_form.input :last_name %>
22
- <% end %>
23
-
24
- <% form.buttons do %>
25
- <%= form.commit_button %>
26
- <% end %>
27
-
28
- <% end %>
@@ -1,19 +0,0 @@
1
- <% form_for @person do |person_form| %>
2
-
3
- <%= person_form.label :name %>
4
- <%= person_form.text_field :name %>
5
-
6
- <% person_form.fields_for :children do |child_form| %>
7
-
8
- <%= child_form.label :name %>
9
- <%= child_form.text_field :name %>
10
-
11
- <% unless child_form.object.new_record? %>
12
- <%= child_form.check_box '_delete' %>
13
- <%= child_form.label '_delete', 'Remove' %>
14
- <% end %>
15
-
16
- <% end %>
17
-
18
- <%= submit_tag %>
19
- <% end %>
@@ -1,17 +0,0 @@
1
- <%= simple_form_for @user do |f| %>
2
- <%= f.input :username, :label_html => { :class => 'my_class' } %>
3
- <%= f.input :password, :hint => false, :error_html => { :id => "password_error"} %>
4
- <%= f.input :password_confirmation, :label => false %>
5
- <%= f.input :time_zone, :priority => /US/%>
6
- <%= f.error :username, :id => 'user_name_error' %>
7
- <%= f.hint 'No special characters, please!' %>
8
- <%= f.association :company %>
9
- <%= f.association :role %>
10
-
11
- <%= f.association :companies, :as => :radio %>
12
- <%= f.association :roles, :as => :check_boxes %>
13
-
14
- <%= f.button :submit %>
15
- <%= f.button :submit %>
16
- <%= f.submit 'Save' %>
17
- <% end %>
@@ -1,14 +0,0 @@
1
- <ul>
2
- <% for @item in @items -%>
3
- <li><%= @item %></li>
4
- <% end -%>
5
- </ul>
6
- <%= hello :you -%>
7
- <%= hello :me %>
8
-
9
- <ul>
10
- <% for @person in @persons %>
11
- <li><%= @person %></li>
12
- <% end %>
13
- </ul>
14
-