Class: TurboRspec::Matchers::MatchTurboStreamSnapshot
- Inherits:
-
Object
- Object
- TurboRspec::Matchers::MatchTurboStreamSnapshot
- Defined in:
- lib/turbo_rspec/matchers/match_turbo_stream_snapshot.rb
Overview
RSpec matcher that records a turbo stream response on the first run and diffs against the stored snapshot on subsequent runs.
Snapshots are written to the directory configured by +TurboRspec.configuration.snapshot_dir+ (default: +spec/snapshots/turbo+). Each snapshot is stored as +name.turbo+.
Set +UPDATE_TURBO_SNAPSHOTS=1+ to overwrite existing snapshots.
Instance Method Summary collapse
- #description ⇒ String
- #does_not_match?(response_or_body) ⇒ Boolean
- #failure_message ⇒ String
- #failure_message_when_negated ⇒ String
-
#initialize(name) ⇒ MatchTurboStreamSnapshot
constructor
A new instance of MatchTurboStreamSnapshot.
- #matches?(response_or_body) ⇒ Boolean
Constructor Details
#initialize(name) ⇒ MatchTurboStreamSnapshot
Returns a new instance of MatchTurboStreamSnapshot.
19 20 21 |
# File 'lib/turbo_rspec/matchers/match_turbo_stream_snapshot.rb', line 19 def initialize(name) @name = name end |
Instance Method Details
#description ⇒ String
58 59 60 |
# File 'lib/turbo_rspec/matchers/match_turbo_stream_snapshot.rb', line 58 def description "match turbo stream snapshot #{@name.inspect}" end |
#does_not_match?(response_or_body) ⇒ Boolean
40 41 42 |
# File 'lib/turbo_rspec/matchers/match_turbo_stream_snapshot.rb', line 40 def does_not_match?(response_or_body) !matches?(response_or_body) end |
#failure_message ⇒ String
45 46 47 48 49 50 |
# File 'lib/turbo_rspec/matchers/match_turbo_stream_snapshot.rb', line 45 def "expected response to match turbo stream snapshot #{@name.inspect}\n\n" \ "stored:\n#{@stored}\n\n" \ "actual:\n#{@actual}\n\n" \ "To update: run with UPDATE_TURBO_SNAPSHOTS=1" end |
#failure_message_when_negated ⇒ String
53 54 55 |
# File 'lib/turbo_rspec/matchers/match_turbo_stream_snapshot.rb', line 53 def "expected response not to match turbo stream snapshot #{@name.inspect}" end |
#matches?(response_or_body) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/turbo_rspec/matchers/match_turbo_stream_snapshot.rb', line 25 def matches?(response_or_body) @actual = extract_body(response_or_body) @path = snapshot_path if update_snapshots? || !File.exist?(@path) write_snapshot(@actual) true else @stored = File.read(@path) @actual.strip == @stored.strip end end |