wrap_it 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +17 -11
- data/.rspec +2 -0
- data/Gemfile +0 -3
- data/Gemfile.rails4 +5 -0
- data/Gemfile.sinatra +5 -0
- data/README.md +138 -24
- data/Rakefile +14 -1
- data/lib/wrap_it/base.rb +47 -20
- data/lib/wrap_it/callbacks.rb +10 -5
- data/lib/wrap_it/container.rb +91 -38
- data/lib/wrap_it/enums.rb +1 -1
- data/lib/wrap_it/frameworks.rb +24 -0
- data/lib/wrap_it/helpers.rb +74 -0
- data/lib/wrap_it/module_helpers.rb +23 -0
- data/lib/wrap_it/sections.rb +81 -0
- data/lib/wrap_it/switches.rb +11 -10
- data/lib/wrap_it/text_container.rb +6 -1
- data/lib/wrap_it/version.rb +1 -1
- data/lib/wrap_it.rb +9 -63
- data/log/development.log +174 -0
- data/sections_explained.md +70 -0
- data/spec/frameworks/log/development.log +1633 -0
- data/spec/frameworks/rails_app.rb +61 -0
- data/spec/frameworks/sinatra_app.rb +32 -0
- data/spec/{rails → integration}/base_spec.rb +7 -7
- data/spec/integration/container_spec.rb +92 -0
- data/spec/integration/examples_spec.rb +54 -0
- data/spec/integration/text_container_spec.rb +13 -0
- data/spec/lib/base_spec.rb +0 -6
- data/spec/lib/container_spec.rb +1 -6
- data/spec/lib/helpers_spec.rb +26 -0
- data/spec/lib/html_class_spec.rb +2 -2
- data/spec/lib/sections_spec.rb +72 -0
- data/spec/lib/text_container_spec.rb +19 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/example_groups/integration_example_group.rb +72 -0
- data/spec/support/example_groups/wrap_it_example_group.rb +6 -4
- data/wrap_it.gemspec +7 -4
- metadata +49 -25
- data/spec/internal/log/test.log +0 -619
- data/spec/rails/container_spec.rb +0 -30
- data/spec/support/example_groups/rails_example_group.rb +0 -79
@@ -0,0 +1,61 @@
|
|
1
|
+
# require 'rails'
|
2
|
+
# require 'action_controller/railtie'
|
3
|
+
|
4
|
+
# require 'sprockets/railtie'
|
5
|
+
|
6
|
+
require 'action_controller/railtie'
|
7
|
+
require 'action_view/railtie'
|
8
|
+
require 'action_view/base'
|
9
|
+
require 'action_controller/base'
|
10
|
+
|
11
|
+
#
|
12
|
+
# Simple Rails application for testing
|
13
|
+
#
|
14
|
+
#
|
15
|
+
module RailsApp
|
16
|
+
#
|
17
|
+
# App class
|
18
|
+
#
|
19
|
+
class Application < Rails::Application
|
20
|
+
config.secret_token =
|
21
|
+
'572c86f5ede338bd8aba8dae0fd3a326aabababc98d1e6ce34b9f0'
|
22
|
+
|
23
|
+
# config.session_store :cookie_store, key: '_myproject_session'
|
24
|
+
config.active_support.deprecation = :stderr
|
25
|
+
config.root = File.dirname(__FILE__)
|
26
|
+
# config.root = File.join __FILE__, '..'
|
27
|
+
Rails.backtrace_cleaner.remove_silencers!
|
28
|
+
config.cache_store = :memory_store
|
29
|
+
config.consider_all_requests_local = true
|
30
|
+
config.eager_load = false
|
31
|
+
|
32
|
+
config.assets.enabled = false
|
33
|
+
# config.assets.enabled = true if ::Rails::VERSION::MAJOR < 4
|
34
|
+
# config.assets.cache_store =
|
35
|
+
# [:file_store, "#{config.root}/tmp/cache/assets/"]
|
36
|
+
|
37
|
+
routes.draw do
|
38
|
+
get '/test' => 'rails_app/tests#index'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Main controller
|
44
|
+
#
|
45
|
+
# class TestsController < ActionController::Base
|
46
|
+
# helper WrapIt.helpers
|
47
|
+
|
48
|
+
# def index
|
49
|
+
# render inline: @code
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
end
|
53
|
+
|
54
|
+
# configure rails application
|
55
|
+
RailsApp::Application.configure do |app|
|
56
|
+
# app.middleware.use MyRackMiddleware
|
57
|
+
end
|
58
|
+
|
59
|
+
RailsApp::Application.initialize!
|
60
|
+
|
61
|
+
defined?(Capybara) && Capybara.app = RailsApp::Application
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Simple Sinatra application for testing
|
5
|
+
#
|
6
|
+
class SinatraApp < Sinatra::Base
|
7
|
+
enable :sessions
|
8
|
+
|
9
|
+
get '/login' do
|
10
|
+
body 'Please log in'
|
11
|
+
end
|
12
|
+
|
13
|
+
post '/login' do
|
14
|
+
session[:user_email] = params[:user_email]
|
15
|
+
redirect to('/profile')
|
16
|
+
end
|
17
|
+
|
18
|
+
get '/profile' do
|
19
|
+
if user_email == session[:user_email]
|
20
|
+
body "Welcome, #{user_email}!"
|
21
|
+
else
|
22
|
+
redirect to('/login')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# configure sinatra application
|
28
|
+
SinatraApp.configure do |app|
|
29
|
+
# app.use MyRackMiddleware
|
30
|
+
end
|
31
|
+
|
32
|
+
defined?(Capybara) && Capybara.app = SinatraApp
|
@@ -7,19 +7,19 @@ describe WrapIt::Base do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'renders base as div' do
|
10
|
-
render '<%=
|
10
|
+
render '<%= helper %>'
|
11
11
|
expect(rendered).to have_tag 'div', count: 1
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'self.omit_content' do
|
15
15
|
it 'captures block content' do
|
16
|
-
render '<%=
|
16
|
+
render '<%= helper do %>Some text<% end %>'
|
17
17
|
expect(rendered).to have_tag 'div', count: 1, text: /Some text/
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'omits block content with omit_content' do
|
21
21
|
successor_class.class_eval { omit_content }
|
22
|
-
render '<%=
|
22
|
+
render '<%= helper do %>Some text<% end %>'
|
23
23
|
expect(rendered).to have_tag 'div', count: 1, text: ''
|
24
24
|
end
|
25
25
|
end
|
@@ -38,26 +38,26 @@ describe WrapIt::Base do
|
|
38
38
|
|
39
39
|
describe '#wrap' do
|
40
40
|
it 'wraps with WrapIt::Base by default' do
|
41
|
-
render '<%=
|
41
|
+
render '<%= helper(tag: :p) { |s| s.wrap } %>'
|
42
42
|
expect(rendered).to have_tag 'div > p'
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'wraps with WrapIt::Base and creating options' do
|
46
|
-
render '<%=
|
46
|
+
render '<%= helper(tag: :p) { |s| s.wrap tag: :nav } %>'
|
47
47
|
expect(rendered).to have_tag 'nav > p'
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'wraps with class and creating options' do
|
51
51
|
render <<-EOL
|
52
52
|
<% w = Class.new(WrapIt::Base) { switch :sw, html_class: 'act' } %>
|
53
|
-
<%=
|
53
|
+
<%= helper(tag: :p) { |s| s.wrap w, :sw, tag: :nav } %>'
|
54
54
|
EOL
|
55
55
|
expect(rendered).to have_tag 'nav.act > p'
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'wraps with block' do
|
59
59
|
render <<-EOL
|
60
|
-
<%=
|
60
|
+
<%= helper(tag: :p) { |s| s.wrap do
|
61
61
|
|w| w.add_html_class 'nav'
|
62
62
|
end } %>'
|
63
63
|
EOL
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WrapIt::Container do
|
4
|
+
before do
|
5
|
+
successor_class.class_eval do
|
6
|
+
default_tag 'ul'
|
7
|
+
child :item, tag: 'li'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def list_erb(args = '')
|
12
|
+
<<-EOL
|
13
|
+
<%= helper(#{args}) do |s| %>
|
14
|
+
<li class="c1">item 1</li>
|
15
|
+
<% 2.upto 5 do |i| %>
|
16
|
+
<%= s.item class: "c\#{i}" do |_| %>item <%= i %><% end %>
|
17
|
+
<% end %>
|
18
|
+
<li class="c6">item 6</li>
|
19
|
+
<% end %>
|
20
|
+
EOL
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'renders as ul' do
|
24
|
+
render '<%= helper %>'
|
25
|
+
expect(rendered).to have_tag 'ul', count: 1
|
26
|
+
expect(rendered).to_not have_tag 'ul > *'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'renders child items' do
|
30
|
+
render list_erb
|
31
|
+
expect(rendered).to have_tag 'ul > li', count: 6
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'renders child items deffered' do
|
35
|
+
render list_erb(':deffered_render')
|
36
|
+
expect(rendered).to have_tag 'ul > li', count: 6
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'drops content child items with omit_content' do
|
40
|
+
successor_class.class_eval { omit_content }
|
41
|
+
render list_erb
|
42
|
+
expect(rendered).to have_tag 'ul > li', count: 4
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'drops content childs with omit_content and deffered' do
|
46
|
+
successor_class.class_eval { omit_content }
|
47
|
+
render list_erb(':deffered_render')
|
48
|
+
expect(rendered).to have_tag 'ul > li', count: 4
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'child helper method safety' do
|
52
|
+
it 'returns string with default options' do
|
53
|
+
expect(successor.item).to be_kind_of String
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns string with omit_content' do
|
57
|
+
successor_class.class_eval { omit_content }
|
58
|
+
expect(successor.item).to be_kind_of String
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns string with deffered' do
|
62
|
+
expect(successor(:deffered_render).item).to be_kind_of String
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns string with deffered and omit' do
|
66
|
+
successor_class.class_eval { omit_content }
|
67
|
+
expect(successor(:deffered_render).item).to be_kind_of String
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'not collects children without deffered_render' do
|
72
|
+
successor.item
|
73
|
+
expect(successor.children.size).to eq 0
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'collects children with deffered_render' do
|
77
|
+
successor(:deffered_render).item
|
78
|
+
expect(successor.children.size).to eq 1
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'avoids changing deffered_render after first item added' do
|
82
|
+
successor(:deffered_render).item
|
83
|
+
successor.deffered_render = false
|
84
|
+
expect(successor.deffered_render?).to be_true
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'extracts one child from optioins' do
|
88
|
+
successor_class.class_eval { extract_from_options :item, :item }
|
89
|
+
render '<%= helper item: {class: "list-item"} %>'
|
90
|
+
expect(rendered).to have_tag 'ul > li.list-item', count: 1
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WrapIt::Base do
|
4
|
+
describe 'usage exmaples' do
|
5
|
+
describe 'sections_explained' do
|
6
|
+
it '#1' do
|
7
|
+
successor_class.class_eval do
|
8
|
+
section :append, :prepend
|
9
|
+
place :prepend, before: :content
|
10
|
+
place :append, after: :content
|
11
|
+
after_initialize do
|
12
|
+
@prepend = options.delete(:prepend)
|
13
|
+
@append = options.delete(:append)
|
14
|
+
end
|
15
|
+
after_capture do
|
16
|
+
unless @prepend.nil?
|
17
|
+
self[:prepend] = content_tag('span', @prepend,
|
18
|
+
class: 'input-group-addon')
|
19
|
+
end
|
20
|
+
unless @append.nil?
|
21
|
+
self[:append] = content_tag('span', @append,
|
22
|
+
class: 'input-group-addon')
|
23
|
+
end
|
24
|
+
if self[:content].empty?
|
25
|
+
options[:type] = 'text'
|
26
|
+
add_html_class 'form-control'
|
27
|
+
self[:content] = content_tag('input', '', options)
|
28
|
+
options.clear
|
29
|
+
add_html_class 'input-group'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
render <<-EOL
|
34
|
+
<%= helper prepend: '@', placeholder: 'Username' %>
|
35
|
+
<%= helper append: '.00' %>
|
36
|
+
<%= helper append: '.00', prepend: '$' %>
|
37
|
+
EOL
|
38
|
+
expect(rendered).to have_tag(
|
39
|
+
'div.input-group > span.input-group-addon[text()="@"]' \
|
40
|
+
' + input.form-control[@type="text"][@placeholder="Username"]'
|
41
|
+
)
|
42
|
+
expect(rendered).to have_tag(
|
43
|
+
'div.input-group > input.form-control[@type="text"]' \
|
44
|
+
' + span.input-group-addon[text()=".00"]'
|
45
|
+
)
|
46
|
+
expect(rendered).to have_tag(
|
47
|
+
'div.input-group > span.input-group-addon[text()="$"]' \
|
48
|
+
' + input.form-control[@type="text"]' \
|
49
|
+
' + span.input-group-addon[text()=".00"]'
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WrapIt::TextContainer do
|
4
|
+
it 'renders body' do
|
5
|
+
render '<%= helper "text" %>'
|
6
|
+
expect(rendered).to have_tag 'p', text: 'text'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'places body from options prior to captured content' do
|
10
|
+
render '<%= helper "text" do %> with content<% end %>'
|
11
|
+
expect(rendered).to have_tag 'p', text: 'text with content'
|
12
|
+
end
|
13
|
+
end
|
data/spec/lib/base_spec.rb
CHANGED
@@ -14,12 +14,6 @@ describe WrapIt::Base do
|
|
14
14
|
expect(successor(tag: 'p').tag).to eq 'p'
|
15
15
|
end
|
16
16
|
|
17
|
-
it 'drops @arguments after init' do
|
18
|
-
expect(
|
19
|
-
successor.instance_variable_get(:@arguments)
|
20
|
-
).to be_nil
|
21
|
-
end
|
22
|
-
|
23
17
|
it 'extends @arguments with ArgumentsArray module' do
|
24
18
|
args = nil
|
25
19
|
successor_class.class_eval { after_initialize { args = @arguments } }
|
data/spec/lib/container_spec.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WrapIt::Container do
|
4
|
-
# it '
|
5
|
-
# successor_class.class_eval { child :test, [tag: 'li'] }
|
6
|
-
# successor.test
|
7
|
-
# expect(successor.instance_variable_get(:@children).size).to eq 1
|
4
|
+
# it 'not collects children without deffered_render' do
|
8
5
|
# end
|
9
|
-
|
10
|
-
pending 'adds safe helpers'
|
11
6
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WrapIt do
|
4
|
+
describe 'self.register_module' do
|
5
|
+
it 'registers existing module' do
|
6
|
+
mod = Module.new
|
7
|
+
expect(WrapIt.register_module(mod)).to eq mod
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'makes anonymous module if no module specified' do
|
11
|
+
expect(WrapIt.register_module).to be_kind_of Module
|
12
|
+
end
|
13
|
+
|
14
|
+
%i(register unregister).each do |method|
|
15
|
+
it "adds `#{method}` method to module" do
|
16
|
+
expect(WrapIt.register_module).to respond_to method
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'supports prefix for helpers' do
|
21
|
+
mod = WrapIt.register_module prefix: 'test_'
|
22
|
+
mod.register :method, Object
|
23
|
+
expect(mod.instance_methods).to include :test_method
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/lib/html_class_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe WrapIt::HTMLClass do
|
|
7
7
|
wrapper_class.class_eval { html_class :a, [:b, 'c'] }
|
8
8
|
expect(wrapper.html_class).to eq %w(a b c)
|
9
9
|
sub_class = Class.new(wrapper_class) { html_class :a, [:d, 'e'] }
|
10
|
-
expect(sub_class.new(
|
10
|
+
expect(sub_class.new(template_wrapper).html_class).to eq %w(a d e b c)
|
11
11
|
end
|
12
12
|
|
13
13
|
describe '#html_class_prefix' do
|
@@ -23,7 +23,7 @@ describe WrapIt::HTMLClass do
|
|
23
23
|
it 'returns derived value' do
|
24
24
|
wrapper_class.class_eval { html_class_prefix 'e-' }
|
25
25
|
sub_class = Class.new(wrapper_class)
|
26
|
-
expect(sub_class.new(
|
26
|
+
expect(sub_class.new(template_wrapper).html_class_prefix).to eq 'e-'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WrapIt::Sections do
|
4
|
+
it_behaves_like 'Base module'
|
5
|
+
|
6
|
+
describe 'self.section' do
|
7
|
+
it 'adds sections' do
|
8
|
+
wrapper_class.send(:section, :test, :section)
|
9
|
+
expect(wrapper_class.sections).to include :test, :section
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'drops duplicated sections' do
|
13
|
+
wrapper_class.send(:section, :test, :section, :test)
|
14
|
+
expect(wrapper_class.sections.size).to eq WrapIt::Base.sections.size + 2
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'drops :begin and :end sections' do
|
18
|
+
wrapper_class.send(:section, :begin, :end)
|
19
|
+
expect(wrapper_class.sections.size).to eq WrapIt::Base.sections.size
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'adds section to the end of placement' do
|
23
|
+
wrapper_class.section(:test)
|
24
|
+
expect(wrapper_class.placement.last).to eq :test
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'self.sections' do
|
29
|
+
it 'combines sections with derived' do
|
30
|
+
wrapper_class.send(:section, :test)
|
31
|
+
expect(wrapper_class.sections)
|
32
|
+
.to match_array(WrapIt::Base.sections + [:test])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'self.placement' do
|
37
|
+
it 'sets places as parent placement + @sections for Base subclasses' do
|
38
|
+
wrapper_class.section(:test)
|
39
|
+
wrapper_class.place(:test, after: wrapper_class.placement.first)
|
40
|
+
expect(Class.new(wrapper_class).placement).to eq wrapper_class.placement
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'clones sections' do
|
44
|
+
wrapper_class.placement
|
45
|
+
wrapper_class.instance_variable_get(:@placement).pop
|
46
|
+
expect(wrapper_class.placement.size)
|
47
|
+
.to eq wrapper_class.sections.size - 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'self.place' do
|
52
|
+
it 'places items right' do
|
53
|
+
wrapper_class.section(:test)
|
54
|
+
wrapper_class.place(:test, after: :begin)
|
55
|
+
expect(wrapper_class.placement.first).to eq :test
|
56
|
+
wrapper_class.place(:test, before: :end)
|
57
|
+
expect(wrapper_class.placement.last).to eq :test
|
58
|
+
first = wrapper_class.placement.first
|
59
|
+
wrapper_class.place(:test, after: first)
|
60
|
+
expect(wrapper_class.placement[1]).to eq :test
|
61
|
+
wrapper_class.place(:test, before: first)
|
62
|
+
expect(wrapper_class.placement.first).to eq :test
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'adds hash-like access' do
|
67
|
+
wrapper_class.section(:test)
|
68
|
+
expect(wrapper[:test]).to eq ''
|
69
|
+
wrapper[:test] << 'test'
|
70
|
+
expect(wrapper[:test]).to eq 'test'
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WrapIt::TextContainer do
|
4
|
+
it { expect(wrapper_class.default_tag).to eq 'p' }
|
5
|
+
|
6
|
+
%i(text body).each do |option|
|
7
|
+
it "gets text from `#{option}` option" do
|
8
|
+
expect(wrapper(option => 'text').body).to eq 'text'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "cleanups `#{option}` for options" do
|
12
|
+
expect(wrapper(option => 'text').options).to_not include option
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'gets text from first String argument' do
|
17
|
+
expect(wrapper(:symbol, 'text', 'other').body).to eq 'text'
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,14 @@ require 'bundler'
|
|
3
3
|
|
4
4
|
Bundler.require :default, :development
|
5
5
|
|
6
|
+
if /sinatra/ =~ ENV['FRAMEWORK']
|
7
|
+
require File.join(File.dirname(__FILE__), 'frameworks', 'sinatra_app.rb')
|
8
|
+
FRAMEWORK = :sinatra
|
9
|
+
elsif /rails/ =~ ENV['FRAMEWORK']
|
10
|
+
require File.join(File.dirname(__FILE__), 'frameworks', 'rails_app.rb')
|
11
|
+
FRAMEWORK = :rails
|
12
|
+
end
|
13
|
+
|
6
14
|
Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each do |file|
|
7
15
|
require file
|
8
16
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Helpers for integration testing
|
3
|
+
#
|
4
|
+
# @author Alexey Ovchinnikov <alexiss@cybernetlab.ru>
|
5
|
+
#
|
6
|
+
module IntegrationExampleGroup
|
7
|
+
def self.included(base)
|
8
|
+
base.instance_eval do
|
9
|
+
metadata[:type] = :integration
|
10
|
+
|
11
|
+
after do
|
12
|
+
if Object.const_defined?(:Successor)
|
13
|
+
Object.send(:remove_const, :Successor)
|
14
|
+
end
|
15
|
+
Object.send(:remove_const, :Wrapper) if Object.const_defined?(:Wrapper)
|
16
|
+
end
|
17
|
+
|
18
|
+
if WrapIt.rails?
|
19
|
+
let(:template) do
|
20
|
+
@context ||= ActionView::LookupContext.new(
|
21
|
+
RailsApp::Application.root
|
22
|
+
)
|
23
|
+
template_class.new(ActionView::TemplateRenderer.new(@context))
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:template_class) do
|
27
|
+
mod = helpers_module
|
28
|
+
Class.new(ActionView::Base) do
|
29
|
+
include mod
|
30
|
+
end
|
31
|
+
end
|
32
|
+
else
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:rendered) { @rendered }
|
36
|
+
|
37
|
+
let(:helpers_module) do
|
38
|
+
Object.send(:remove_const, :Helpers) if Object.const_defined?(:Helpers)
|
39
|
+
Object.send(:const_set, :Helpers, WrapIt.register_module)
|
40
|
+
if described_class.is_a?(Class)
|
41
|
+
if Object.const_defined?(:Successor)
|
42
|
+
Object.send(:remove_const, :Successor)
|
43
|
+
end
|
44
|
+
Object.const_set(:Successor, successor_class)
|
45
|
+
Helpers.register :helper, 'Successor'
|
46
|
+
else
|
47
|
+
if Object.const_defined?(:Wrapper)
|
48
|
+
Object.send(:remove_const, :Wrapper)
|
49
|
+
end
|
50
|
+
Object.const_set(:Wrapper, wrapper_class)
|
51
|
+
Helpers.register :helper, 'Wrapper'
|
52
|
+
end
|
53
|
+
Helpers
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def render(code)
|
59
|
+
if WrapIt.rails?
|
60
|
+
@rendered = template.render(inline: code)
|
61
|
+
else
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
RSpec.configure do |config|
|
66
|
+
config.include(
|
67
|
+
self,
|
68
|
+
type: :integration,
|
69
|
+
example_group: { file_path: /spec\/integration/ }
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
module WrapItExampleGroup
|
7
7
|
BASE_MODULES = [WrapIt::HTMLClass, WrapIt::HTMLData, WrapIt::Switches,
|
8
|
-
WrapIt::Enums, WrapIt::Renderer]
|
8
|
+
WrapIt::Enums, WrapIt::Renderer, WrapIt::Sections]
|
9
9
|
|
10
10
|
def self.included(base)
|
11
11
|
base.instance_eval do
|
@@ -16,7 +16,7 @@ module WrapItExampleGroup
|
|
16
16
|
@wrapper = nil
|
17
17
|
end
|
18
18
|
|
19
|
-
let(:
|
19
|
+
let(:template_wrapper) { Object.new }
|
20
20
|
|
21
21
|
let(:successor_class) { Class.new described_class }
|
22
22
|
|
@@ -32,11 +32,13 @@ module WrapItExampleGroup
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def successor(*args, &block)
|
35
|
-
|
35
|
+
templ = respond_to?(:template) ? template : template_wrapper
|
36
|
+
@successor ||= successor_class.new(templ, *args, &block)
|
36
37
|
end
|
37
38
|
|
38
39
|
def wrapper(*args, &block)
|
39
|
-
|
40
|
+
templ = respond_to?(:template) ? template : template_wrapper
|
41
|
+
@wrapper ||= wrapper_class.new(templ, *args, &block)
|
40
42
|
end
|
41
43
|
|
42
44
|
RSpec.configure do |config|
|
data/wrap_it.gemspec
CHANGED
@@ -15,6 +15,9 @@ Gem::Specification.new do |spec|
|
|
15
15
|
EOL
|
16
16
|
spec.homepage = 'https://github.com/cybernetlab/wrap_it'
|
17
17
|
spec.license = 'MIT'
|
18
|
+
spec.metadata = {
|
19
|
+
'issue_tracker' => 'https://github.com/cybernetlab/wrap_it/issues'
|
20
|
+
}
|
18
21
|
|
19
22
|
spec.files = `git ls-files`.split($/)
|
20
23
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -22,9 +25,9 @@ Gem::Specification.new do |spec|
|
|
22
25
|
spec.require_paths = ['lib']
|
23
26
|
|
24
27
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
-
spec.add_development_dependency 'rake'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.1'
|
26
29
|
spec.add_development_dependency 'redcarpet', '~> 1.17'
|
27
|
-
spec.add_development_dependency 'yard', '~> 0.
|
28
|
-
spec.add_development_dependency 'rspec'
|
29
|
-
spec.add_development_dependency 'rspec-html-matchers'
|
30
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 2.14'
|
32
|
+
spec.add_development_dependency 'rspec-html-matchers', '~> 0.4'
|
30
33
|
end
|