Sha256: 23b3aa9a28c23a9c6ed1551c071b72178b432949a23bcb1139cd4334e070e2f0

Contents?: true

Size: 1.87 KB

Versions: 84

Compression:

Stored size: 1.87 KB

Contents

require "rspec"
require "pry"
require "fakeweb"
require "onebox"
require 'mocha/api'

require_relative "support/html_spec_helper"

RSpec.configure do |config|
  config.before(:all) do
    FakeWeb.allow_net_connect = false
  end
  config.include HTMLSpecHelper
end

shared_context "engines" do
  before(:each) do
    fake(@uri || @link, response(described_class.onebox_name))
    @onebox = described_class.new(@link)
    @html = @onebox.to_html
    @data = Onebox::Helpers.symbolize_keys(@onebox.send(:data))
  end
  before(:each) { Onebox.options.cache.clear }

  let(:onebox) { @onebox }
  let(:html) { @html }
  let(:data) { @data }
  let(:link) { @link }

  def escaped_data(key)
    CGI.escapeHTML(data[key])
  end
end

shared_examples_for "an engine" do
  it "responds to data" do
    expect(described_class.private_instance_methods).to include(:data)
  end

  it "responds to record" do
    expect(described_class.private_instance_methods).to include(:record)
  end

  it "correctly matches the url" do
    onebox = Onebox::Matcher.new(link).oneboxed
    expect(onebox).to be(described_class)
  end

  describe "#data" do
    it "includes title" do
      expect(data[:title]).not_to be_nil
    end

    it "includes link" do
      expect(data[:link]).not_to be_nil
    end
  end
end

shared_examples_for "a layout engine" do
  describe "#to_html" do
    it "includes subname" do
      expect(html).to include(%|<aside class="onebox #{described_class.onebox_name}">|)
    end

    it "includes title" do
      expect(html).to include(escaped_data(:title))
    end

    it "includes link" do
      expect(html).to include(%|class="link" href="#{data[:link]}|)
    end

    it "includes badge" do
      expect(html).to include(%|<strong class="name">#{data[:badge]}</strong>|)
    end

    it "includes domain" do
      expect(html).to include(%|class="domain" href="#{escaped_data(:domain)}|)
    end
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
onebox-1.5.50 spec/spec_helper.rb
onebox-1.5.49 spec/spec_helper.rb
onebox-1.5.48 spec/spec_helper.rb
onebox-1.5.47 spec/spec_helper.rb
onebox-1.5.45 spec/spec_helper.rb
onebox-1.5.44 spec/spec_helper.rb
onebox-1.5.43 spec/spec_helper.rb
onebox-1.5.42 spec/spec_helper.rb
onebox-1.5.41 spec/spec_helper.rb
onebox-1.5.40 spec/spec_helper.rb
onebox-1.5.39 spec/spec_helper.rb
onebox-1.5.38 spec/spec_helper.rb
onebox-1.5.37 spec/spec_helper.rb
onebox-1.5.36 spec/spec_helper.rb
onebox-1.5.35 spec/spec_helper.rb
onebox-1.5.34 spec/spec_helper.rb
onebox-1.5.33 spec/spec_helper.rb
onebox-1.5.32 spec/spec_helper.rb
onebox-1.5.31 spec/spec_helper.rb
onebox-1.5.30 spec/spec_helper.rb