Class: TurboRspec::Matchers::HaveTurboFrame

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_rspec/matchers/have_turbo_frame.rb

Overview

RSpec matcher for asserting that a response body contains a ++ element. Use in request or controller specs.

Examples:

Basic usage

expect(response).to have_turbo_frame

With constraints

expect(response).to have_turbo_frame
  .with_id("messages")
  .with_content("Hello")

See Also:

Instance Method Summary collapse

Constructor Details

#initializeHaveTurboFrame

Returns a new instance of HaveTurboFrame.



20
21
22
23
24
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 20

def initialize
  @id = nil
  @content = nil
  @partial = nil
end

Instance Method Details

#descriptionObject



74
75
76
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 74

def description
  "have turbo frame#{constraint_description}"
end

#does_not_match?(response_or_body) ⇒ Boolean

Parameters:

  • response_or_body (#body, String)

Returns:

  • (Boolean)


60
61
62
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 60

def does_not_match?(response_or_body)
  !matches?(response_or_body)
end

#failure_messageString

Returns:

  • (String)


65
66
67
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 65

def failure_message
  "expected response to contain a turbo frame#{constraint_description}\n#{found_frames_message}"
end

#failure_message_when_negatedString

Returns:

  • (String)


70
71
72
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 70

def failure_message_when_negated
  "expected response not to contain a turbo frame#{constraint_description}"
end

#matches?(response_or_body) ⇒ Boolean

Parameters:

  • response_or_body (#body, String)

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 52

def matches?(response_or_body)
  @body = extract_body(response_or_body)
  @frames = parse_frames(@body)
  @frames.any? { |frame| frame_matches?(frame) }
end

#rendering(partial) ⇒ self

Constrains the match to frames whose HTML includes the given partial path.

Parameters:

  • partial (String)

Returns:

  • (self)


45
46
47
48
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 45

def rendering(partial)
  @partial = partial.to_s
  self
end

#with_content(text) ⇒ self

Constrains the match to frames whose content includes the given text.

Parameters:

  • text (String)

Returns:

  • (self)


37
38
39
40
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 37

def with_content(text)
  @content = text.to_s
  self
end

#with_id(id) ⇒ self

Constrains the match to frames with the given id attribute.

Parameters:

  • id (String)

Returns:

  • (self)


29
30
31
32
# File 'lib/turbo_rspec/matchers/have_turbo_frame.rb', line 29

def with_id(id)
  @id = id.to_s
  self
end