rails-intest-views 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +23 -0
- data/README.md +102 -0
- data/lib/rails-intest-views/capybara_helpers.rb +10 -0
- data/lib/rails-intest-views/engine.rb +22 -0
- data/lib/rails-intest-views/request_helpers.rb +10 -0
- data/lib/rails-intest-views/version.rb +5 -0
- data/lib/rails-intest-views.rb +65 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b1d491795e9f51c9bb4aba566876020a7662989a48ce86c915d047b03ed15f76
|
4
|
+
data.tar.gz: bf1e538af19e4bce5a0a2f2db8b0d9ba01a609f8e353be9048a20cbac0a23112
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9845f89fdaf2a4c9792ad6e2ca98878d73a10aed228cdbd1efb695bad0d8246ea7d8647a9f4853e179ffc37bc581a9f85c6b49b9ea482d1951a4fc8d806e4861
|
7
|
+
data.tar.gz: 71a9610b7019d34b900435e76b8f7b21bb87b34ed32c97183254221e2ad00a1e1e0866fd894c43034966dbd1576e36ecc4bdc05c4c01fa70b2984ec08ffca720
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2023 Vladimir Dementyev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/rails-intest-views.svg)](https://rubygems.org/gems/rails-intest-views)
|
2
|
+
[![Build](https://github.com/palkan/rails-intest-views/workflows/Build/badge.svg)](https://github.com/palkan/rails-intest-views/actions)
|
3
|
+
|
4
|
+
# Rails Intest Views
|
5
|
+
|
6
|
+
Generate test views (templates) right from test files. Useful to test UI components (view components, partials, JS, etc.) in isolation.
|
7
|
+
|
8
|
+
A quick example of using an inline template to test view components via Rails system tests:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
class ButtonComponentSystemTest < ApplicationSystemTestCase
|
12
|
+
def test_submit_button
|
13
|
+
visit_template <<~ERB
|
14
|
+
<form id="myForm" onsubmit="event.preventDefault(); this.innerHTML = '';">
|
15
|
+
<h2>Self-destructing form</h2>
|
16
|
+
<%= render ButtonComponent.new(type: :submit) do %>
|
17
|
+
Save me!
|
18
|
+
<% end %>
|
19
|
+
</form>
|
20
|
+
ERB
|
21
|
+
|
22
|
+
assert_text("Self-destructing form")
|
23
|
+
|
24
|
+
click_button("Save me!")
|
25
|
+
|
26
|
+
assert_no_text("Self-destructing form")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
Adding gem to your Gemfile:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# Gemfile
|
37
|
+
gem "rails-intest-views", group: :test
|
38
|
+
```
|
39
|
+
|
40
|
+
### Supported Ruby/Rails versions
|
41
|
+
|
42
|
+
- Ruby (MRI) >= 2.7.0
|
43
|
+
- Rails 6+
|
44
|
+
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
To use intest templates with Capybara, you must first include the helper module:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# Minitest
|
51
|
+
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
52
|
+
include RailsIntestViews::CapybaraHelpers
|
53
|
+
|
54
|
+
# ...
|
55
|
+
end
|
56
|
+
|
57
|
+
# RSpec
|
58
|
+
RSpec.configure do |config|
|
59
|
+
config.include RailsIntestViews::CapybaraHelpers, type: :system
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
Then, you can use the `#visit_template` helper in your tests:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
visit_template <<~ERB
|
67
|
+
<a href="#">Clicko!</a>
|
68
|
+
ERB
|
69
|
+
|
70
|
+
# some assertions/expectations
|
71
|
+
```
|
72
|
+
|
73
|
+
You can also specify the layout to use:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
source = <<~ERB
|
77
|
+
<a href="#">Clicko!</a>
|
78
|
+
ERB
|
79
|
+
|
80
|
+
visit_template source, layout: "custom"
|
81
|
+
```
|
82
|
+
|
83
|
+
### Configuration
|
84
|
+
|
85
|
+
The following configuration parameters are available (the default values are shown):
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
# a controller class used to render templates
|
89
|
+
config.rails_intest_views.templates_controller = "RailsIntestViews::TemplatesController"
|
90
|
+
# default layout to use; no layout by default (but you're likely to specify it to load scripts, styles, etc.)
|
91
|
+
config.rails_intest_views.default_layout = nil
|
92
|
+
# the mount path for the endpoint (the "/templates/:id" is added to the final URL)
|
93
|
+
config.rails_intest_views.mount_path = "/rails/intest"
|
94
|
+
```
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/palkan/rails-intest-views](https://github.com/palkan/rails-intest-views).
|
99
|
+
|
100
|
+
## License
|
101
|
+
|
102
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsIntestViews # :nodoc:
|
4
|
+
class Engine < ::Rails::Engine # :nodoc:
|
5
|
+
config.rails_intest_views = RailsIntestViews.config
|
6
|
+
|
7
|
+
config.after_initialize do |app|
|
8
|
+
options = app.config.rails_intest_views
|
9
|
+
|
10
|
+
app.routes.prepend do
|
11
|
+
templates_controller = options.templates_controller.sub(/Controller$/, "").underscore
|
12
|
+
|
13
|
+
get(
|
14
|
+
File.join(options.mount_path, ":id"),
|
15
|
+
to: "#{templates_controller}#show",
|
16
|
+
as: :rails_intest_view,
|
17
|
+
internal: true
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "mutex_m"
|
4
|
+
|
5
|
+
module RailsIntestViews
|
6
|
+
class Configuration
|
7
|
+
attr_accessor :templates_controller, :default_layout, :mount_path
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@mount_path = "/rails/intest"
|
11
|
+
@templates_controller = "RailsIntestViews::TemplatesController"
|
12
|
+
@default_layout = nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
@@mutex = Mutex.new
|
18
|
+
@@store = {}
|
19
|
+
|
20
|
+
def config
|
21
|
+
@config ||= Configuration.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def find(id)
|
25
|
+
@@mutex.synchronize do
|
26
|
+
@@store[id]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def write(template, **options)
|
31
|
+
id = nil
|
32
|
+
attempts = 5
|
33
|
+
catch(:done) do
|
34
|
+
loop do
|
35
|
+
id = SecureRandom.hex(6)
|
36
|
+
|
37
|
+
@@mutex.synchronize do
|
38
|
+
if @@store[id]
|
39
|
+
attempts -= 1
|
40
|
+
id = nil
|
41
|
+
throw :done if attempts < 0
|
42
|
+
next
|
43
|
+
else
|
44
|
+
@@store[id] = {template: template, **options}
|
45
|
+
throw :done
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
raise "Failed to write template" if id.nil?
|
52
|
+
id
|
53
|
+
end
|
54
|
+
|
55
|
+
def url_for(id)
|
56
|
+
File.join(config.mount_path, id)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
autoload :RequestHelpers, "rails-intest-views/request_helpers"
|
61
|
+
autoload :CapybaraHelpers, "rails-intest-views/capybara_helpers"
|
62
|
+
end
|
63
|
+
|
64
|
+
require "rails-intest-views/version"
|
65
|
+
require "rails-intest-views/engine" if defined?(Rails::Engine)
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-intest-views
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vladimir Dementyev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: combustion
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-focus
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-reporters
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Generate view templates dynamically in Rails tests
|
98
|
+
email:
|
99
|
+
- Vladimir Dementyev
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- CHANGELOG.md
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- lib/rails-intest-views.rb
|
108
|
+
- lib/rails-intest-views/capybara_helpers.rb
|
109
|
+
- lib/rails-intest-views/engine.rb
|
110
|
+
- lib/rails-intest-views/request_helpers.rb
|
111
|
+
- lib/rails-intest-views/version.rb
|
112
|
+
homepage: https://github.com/palkan/rails-intest-views
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata:
|
116
|
+
bug_tracker_uri: https://github.com/palkan/rails-intest-views/issues
|
117
|
+
changelog_uri: https://github.com/palkan/rails-intest-views/blob/master/CHANGELOG.md
|
118
|
+
documentation_uri: https://github.com/palkan/rails-intest-views
|
119
|
+
homepage_uri: https://github.com/palkan/rails-intest-views
|
120
|
+
source_code_uri: https://github.com/palkan/rails-intest-views
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '2.7'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubygems_version: 3.4.20
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Generate view templates dynamically in Rails tests
|
140
|
+
test_files: []
|