Sha256: 0a44449b7ef00cf03df1f06bfbd42b34a8c5592f98469d2b6cd868515539c42e

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require "spec_helper"

describe Lita::Template do
  describe ".from_file" do
    context "with a path to an ERB template" do
      subject do
        described_class.from_file(File.expand_path("../templates/basic.erb", __dir__))
      end

      it "uses the source in the file" do
        expect(subject.render).to eq("Template rendered from a file!")
      end
    end
  end

  describe "#add_helper" do
    subject { described_class.new("<%= reverse_name(@first, @last) %>") }
    let(:helper) do
      Module.new do
        def reverse_name(first, last)
          "#{last}, #{first}"
        end
      end
    end

    it "adds the helper to the evaluation context" do
      subject.add_helper(helper)

      expect(subject.render(first: "Carl", last: "Pug")).to eq("Pug, Carl")
    end
  end

  describe "#render" do
    context "with a static source template" do
      subject { described_class.new("Hello, Lita!") }

      it "renders the text" do
        expect(subject.render).to eq("Hello, Lita!")
      end
    end

    context "with interpolation variables" do
      subject { described_class.new("Hello, <%= @name %>!") }

      it "renders the text with interpolated values" do
        expect(subject.render(name: "Carl")).to eq("Hello, Carl!")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rita-5.0.0.alpha.4 spec/lita/template_spec.rb
rita-5.0.0.alpha.3 spec/lita/template_spec.rb
rita-5.0.0.alpha.2 spec/lita/template_spec.rb
rita-5.0.0.alpha.1 spec/lita/template_spec.rb