Skip to content

Commit

Permalink
WIP: Adding tests for Phlex::HtmlRenderable
Browse files Browse the repository at this point in the history
  • Loading branch information
iachettifederico committed Jan 20, 2024
1 parent a5174dc commit 5d6b6dd
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fixtures/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ def view(&block)
end
end

def html_renderable_view(...)
let :view do
Class.new(Phlex::HTML) do
include Phlex::HtmlRenderable

class_eval(...)
end
end
end

def svg_view(&block)
let :view do
Class.new(Phlex::SVG, &block)
Expand Down
53 changes: 53 additions & 0 deletions test/phlex/html_renderable/plain.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

describe Phlex::HTML do
extend ViewHelper

with "text" do
html_renderable_view do
def template
plain "Hi"
end
end

it "produces the correct output" do
expect(output).to be == "Hi"
end
end

with "int as text" do
view do
def template
plain 1
end
end

it "produces the correct output" do
expect(output).to be == "1"
end
end

with "float as text" do
view do
def template
plain 2.0
end
end

it "produces the correct output" do
expect(output).to be == "2.0"
end
end

with "an object that has no special format_object handling" do
view do
def template
plain Object.new
end
end

it "raises an ArgumentError" do
expect { output }.to raise_exception(ArgumentError)
end
end
end

0 comments on commit 5d6b6dd

Please sign in to comment.