rao-view_helper 0.0.18.pre → 0.0.19.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/view_helpers/rao/view_helper/base.rb +4 -0
- data/lib/rao/view_helper/spec_helper.rb +33 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f41a651613804f334cc68670b5c5c89a9c63cdad0d85235774862a1bf0889d7
|
4
|
+
data.tar.gz: 26cb3a5fb539b9fa7a29d1f67e0f81db58c260878a98f3aaf85897d3e5543114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69e90d4dca7a984e7892862ad92cfedcf08c1314ff9361158586d8a53e836826e6291e6cafbb7ec08237cc5deedab4404606f9ed4f07b8085325311a5903d488
|
7
|
+
data.tar.gz: c10022f62b93f6fdd62d87b2d278818f2c258edc8abb49469cd5a1c0107ef43e7429ff0e70ff6076a2aca479d7c81ca52ef93e6976e0c6e85ff67a82c6e35c92
|
@@ -13,10 +13,24 @@ module Rao
|
|
13
13
|
#
|
14
14
|
# Usage:
|
15
15
|
#
|
16
|
-
# # spec/
|
16
|
+
# # spec/view_helpers/blorgh/application_view_helper_spec.rb
|
17
17
|
# require 'rails_helper'
|
18
18
|
#
|
19
19
|
# RSpec.describe Blorgh::ApplicationViewHelper, type: :view_helper do
|
20
|
+
# let(:posts) { create_list(:posts, 3) }
|
21
|
+
# let(:options) { {} }
|
22
|
+
# let(:args) { [posts, options] }
|
23
|
+
#
|
24
|
+
# # if your view_helper depends on other view helpers you can register
|
25
|
+
# # them by calling register_view_helper the same way you'd call
|
26
|
+
# # view_helper in a controller.
|
27
|
+
# before(:each) do
|
28
|
+
# register_view_helper Cmor::Core::MarkupViewHelper, as: :markup_helper
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # if you need to change the default_url_options you may do so like this
|
32
|
+
# let(:default_url_options) { { host: 'example.org' } }
|
33
|
+
#
|
20
34
|
# describe 'posts' do
|
21
35
|
# it { expect(rendered).to have_xpath("//div[@id='blorgh-posts']") }
|
22
36
|
# end
|
@@ -29,15 +43,33 @@ module Rao
|
|
29
43
|
mod.let(:view) { ActionView::Base.new(view_paths, assigns) }
|
30
44
|
mod.let(:view_helper) { described_class.new(view) }
|
31
45
|
mod.let(:method_name) { |e| e.metadata[:example_group][:description].to_sym }
|
46
|
+
mod.let(:default_url_options) { { host: 'localhost:3000' } }
|
32
47
|
mod.let(:rendered) {
|
33
48
|
if respond_to?(:options)
|
34
49
|
Capybara::Node::Simple.new(subject.send(method_name, options))
|
50
|
+
elsif respond_to?(:args)
|
51
|
+
Capybara::Node::Simple.new(subject.send(method_name, *args))
|
35
52
|
else
|
36
53
|
Capybara::Node::Simple.new(subject.send(method_name))
|
37
54
|
end
|
38
55
|
}
|
56
|
+
|
57
|
+
mod.before(:each) { view.class.send(:define_method, :main_app, -> { Rails.application.class.routes.url_helpers }) }
|
58
|
+
mod.around(:each) do |example|
|
59
|
+
original_default_url_options = Rails.application.routes.default_url_options
|
60
|
+
Rails.application.routes.default_url_options = default_url_options
|
61
|
+
example.run
|
62
|
+
Rails.application.routes.default_url_options = original_default_url_options
|
63
|
+
end
|
39
64
|
|
40
65
|
mod.subject { view_helper }
|
66
|
+
|
67
|
+
mod.send(:define_method, :register_view_helper) do |klass, options = {}|
|
68
|
+
method_name = options.delete(:as) || klass.name.underscore.gsub('/', '_')
|
69
|
+
view.class.send(:define_method, method_name) do |context|
|
70
|
+
klass.new(context)
|
71
|
+
end
|
72
|
+
end
|
41
73
|
end
|
42
74
|
end
|
43
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rao-view_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rao
|