Sha256: 083ee045f6a3002a5709b1ab6b7713c6a841869f247786ab82526e102300de39

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

shared_examples_for "roadie asset provider" do |options|
  valid_name = options[:valid_name] or raise "You must provide a :valid_name option to the shared examples"
  invalid_name = options[:invalid_name] or raise "You must provide an :invalid_name option to the shared examples"

  def verify_stylesheet(stylesheet)
    expect(stylesheet).to_not be_nil

    # Name
    expect(stylesheet.name).to be_a(String)
    expect(stylesheet.name).to_not be_empty

    # We do not want to force clients to always return non-empty files.
    # Stylesheet#initialize should crash when given a non-valid CSS (like nil,
    # for example)
    # expect(stylesheet.blocks).to_not be_empty
  end

  it "responds to #find_stylesheet" do
    expect(subject).to respond_to(:find_stylesheet)
    expect(subject.method(:find_stylesheet).arity).to eq 1
  end

  it "responds to #find_stylesheet!" do
    expect(subject).to respond_to(:find_stylesheet!)
    expect(subject.method(:find_stylesheet!).arity).to eq 1
  end

  describe "#find_stylesheet" do
    it "can find a stylesheet" do
      verify_stylesheet subject.find_stylesheet(valid_name)
    end

    it "cannot find an invalid stylesheet" do
      expect(subject.find_stylesheet(invalid_name)).to be_nil
    end
  end

  describe "#find_stylesheet!" do
    it "can find a stylesheet" do
      verify_stylesheet subject.find_stylesheet!(valid_name)
    end

    it "raises Roadie::CssNotFound on invalid stylesheets" do
      expect {
        subject.find_stylesheet!(invalid_name)
      }.to raise_error(
        Roadie::CssNotFound,
        Regexp.new(Regexp.quote(invalid_name))
      )
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
roadie-5.2.1 lib/roadie/rspec/asset_provider.rb
roadie-5.2.0 lib/roadie/rspec/asset_provider.rb
roadie-5.1.0 lib/roadie/rspec/asset_provider.rb
roadie-5.0.1 lib/roadie/rspec/asset_provider.rb
roadie-5.0.0 lib/roadie/rspec/asset_provider.rb