turbo_rspec 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +32 -0
- data/ROADMAP.md +0 -11
- data/lib/turbo_rspec/helpers.rb +17 -0
- data/lib/turbo_rspec/shared_examples.rb +27 -0
- data/lib/turbo_rspec/version.rb +1 -1
- data/lib/turbo_rspec.rb +5 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e6568858c6d2ba4487a184d5161e3a254368447704c86437f7f5753003af0bb
|
|
4
|
+
data.tar.gz: c3b05381ef257037eb0112e3bc925d4db1973780e16d6d56a9cd842db9f4d994
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 710e2a679f38e346a19031c81441b2ce56e0317b5b770275a1d69d1117fb7eb48af0551e1c5c6a62cd4651cdee9cc6976c32ec038472b3dd5beea2d5d978e662
|
|
7
|
+
data.tar.gz: 557f56e9807599846b81204772ec47919daf2621ef090253971f1f9f9390bc5f22a63e438a9c4715dedbb939c44c4c517654852ac41fc87392bee88b4f8ff83d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.6.0] - 2026-05-28
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `TurboRspec::Helpers` module with `turbo_stream_html` and `turbo_frame_html` factory helpers for building test HTML inline
|
|
8
|
+
- Shared examples: `it_behaves_like "a turbo stream response"` and `it_behaves_like "a turbo frame response"` for common assertions
|
|
9
|
+
- `have_turbo_stream`, `have_turbo_frame`, and `TurboRspec::Helpers` auto-included into `type: :controller` example groups alongside `type: :request`
|
|
10
|
+
|
|
3
11
|
## [0.5.0] - 2026-05-28
|
|
4
12
|
|
|
5
13
|
### Added
|
data/README.md
CHANGED
|
@@ -201,6 +201,38 @@ expect(page).to have_turbo_stream_tag("signed_stream_name")
|
|
|
201
201
|
expect(page).not_to have_turbo_stream_tag
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
+
## Test helpers
|
|
205
|
+
|
|
206
|
+
`TurboRspec::Helpers` provides factory methods for building Turbo HTML inline in tests. Auto-included in `type: :request` and `type: :controller` example groups.
|
|
207
|
+
|
|
208
|
+
```ruby
|
|
209
|
+
# Build a <turbo-stream> element
|
|
210
|
+
turbo_stream_html(action: :append, target: "messages", content: "Hello")
|
|
211
|
+
turbo_stream_html(action: :remove, targets: ".item")
|
|
212
|
+
|
|
213
|
+
# Build a <turbo-frame> element
|
|
214
|
+
turbo_frame_html(id: "messages", content: "Hello")
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Shared examples
|
|
218
|
+
|
|
219
|
+
```ruby
|
|
220
|
+
RSpec.describe "Messages", type: :request do
|
|
221
|
+
describe "POST /messages" do
|
|
222
|
+
before { post messages_path, params: { body: "Hello" }, as: :turbo_stream }
|
|
223
|
+
|
|
224
|
+
# Assert any turbo stream is present
|
|
225
|
+
it_behaves_like "a turbo stream response"
|
|
226
|
+
|
|
227
|
+
# Assert a specific stream
|
|
228
|
+
it_behaves_like "a turbo stream response", action: :append, target: "messages", content: "Hello"
|
|
229
|
+
|
|
230
|
+
# Assert a turbo frame
|
|
231
|
+
it_behaves_like "a turbo frame response", id: "messages"
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
```
|
|
235
|
+
|
|
204
236
|
## Example: request spec
|
|
205
237
|
|
|
206
238
|
```ruby
|
data/ROADMAP.md
CHANGED
|
@@ -4,17 +4,6 @@ RSpec matchers for [Turbo](https://github.com/hotwired/turbo-rails): Turbo Strea
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
## v0.6.0 — Testing utilities
|
|
8
|
-
|
|
9
|
-
**Goal:** reduce boilerplate in real test suites and close the controller spec gap.
|
|
10
|
-
|
|
11
|
-
- `turbo_stream_html(action:, target:, content: nil)` — factory helper for building `<turbo-stream>` HTML inline in tests
|
|
12
|
-
- Shared examples: `it_behaves_like "a turbo stream response"` and `"a turbo frame response"` for common assertions
|
|
13
|
-
- Controller spec support — `have_turbo_stream` and `have_turbo_frame` working against `response` in `type: :controller`
|
|
14
|
-
- Auto-include `TurboRspec::Matchers` into `type: :controller` when `turbo-rails` is present
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
7
|
## v0.7.0 — Documentation
|
|
19
8
|
|
|
20
9
|
**Goal:** full docs before freezing the API.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TurboRspec
|
|
4
|
+
module Helpers
|
|
5
|
+
def turbo_stream_html(action:, target: nil, targets: nil, content: nil)
|
|
6
|
+
attrs = "action=\"#{action}\""
|
|
7
|
+
attrs += " target=\"#{target}\"" if target
|
|
8
|
+
attrs += " targets=\"#{targets}\"" if targets
|
|
9
|
+
inner = content ? "<template>#{content}</template>" : "<template></template>"
|
|
10
|
+
"<turbo-stream #{attrs}>#{inner}</turbo-stream>"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def turbo_frame_html(id:, content: nil)
|
|
14
|
+
"<turbo-frame id=\"#{id}\">#{content}</turbo-frame>"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# :nocov:
|
|
4
|
+
if defined?(RSpec)
|
|
5
|
+
# :nocov:
|
|
6
|
+
RSpec.shared_examples "a turbo stream response" do |action: nil, target: nil, targets: nil, content: nil, partial: nil|
|
|
7
|
+
it "responds with a turbo stream" do
|
|
8
|
+
matcher = have_turbo_stream
|
|
9
|
+
matcher.with_action(action) if action
|
|
10
|
+
matcher.targeting(target) if target
|
|
11
|
+
matcher.targeting_all(targets) if targets
|
|
12
|
+
matcher.with_content(content) if content
|
|
13
|
+
matcher.rendering(partial) if partial
|
|
14
|
+
expect(response).to matcher
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
RSpec.shared_examples "a turbo frame response" do |id: nil, content: nil, partial: nil|
|
|
19
|
+
it "responds with a turbo frame" do
|
|
20
|
+
matcher = have_turbo_frame
|
|
21
|
+
matcher.with_id(id) if id
|
|
22
|
+
matcher.with_content(content) if content
|
|
23
|
+
matcher.rendering(partial) if partial
|
|
24
|
+
expect(response).to matcher
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/turbo_rspec/version.rb
CHANGED
data/lib/turbo_rspec.rb
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
require_relative "turbo_rspec/version"
|
|
4
4
|
require_relative "turbo_rspec/configuration"
|
|
5
5
|
require_relative "turbo_rspec/matchers"
|
|
6
|
+
require_relative "turbo_rspec/helpers"
|
|
6
7
|
require_relative "turbo_rspec/assertions"
|
|
8
|
+
require_relative "turbo_rspec/shared_examples"
|
|
7
9
|
require_relative "turbo_rspec/capybara/matchers"
|
|
8
10
|
|
|
9
11
|
module TurboRspec
|
|
@@ -25,6 +27,9 @@ module TurboRspec
|
|
|
25
27
|
def install_rspec_integration(config)
|
|
26
28
|
return unless configuration.auto_include && Gem.loaded_specs.key?("turbo-rails")
|
|
27
29
|
config.include Matchers, type: :request
|
|
30
|
+
config.include Matchers, type: :controller
|
|
31
|
+
config.include Helpers, type: :request
|
|
32
|
+
config.include Helpers, type: :controller
|
|
28
33
|
if Gem.loaded_specs.key?("capybara")
|
|
29
34
|
config.include Capybara::Matchers, type: :system
|
|
30
35
|
config.include Capybara::Matchers, type: :feature
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: turbo_rspec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chuck Smith
|
|
@@ -48,11 +48,13 @@ files:
|
|
|
48
48
|
- lib/turbo_rspec/capybara/matchers/have_turbo_frame.rb
|
|
49
49
|
- lib/turbo_rspec/capybara/matchers/have_turbo_stream_tag.rb
|
|
50
50
|
- lib/turbo_rspec/configuration.rb
|
|
51
|
+
- lib/turbo_rspec/helpers.rb
|
|
51
52
|
- lib/turbo_rspec/matchers.rb
|
|
52
53
|
- lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb
|
|
53
54
|
- lib/turbo_rspec/matchers/have_turbo_frame.rb
|
|
54
55
|
- lib/turbo_rspec/matchers/have_turbo_stream.rb
|
|
55
56
|
- lib/turbo_rspec/matchers/have_turbo_streams.rb
|
|
57
|
+
- lib/turbo_rspec/shared_examples.rb
|
|
56
58
|
- lib/turbo_rspec/version.rb
|
|
57
59
|
- sig/turbo_rspec.rbs
|
|
58
60
|
homepage: https://github.com/eclectic-coding/turbo_rspec
|