Mange / roadie
1
# frozen_string_literal: true
2

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

7 5
  def verify_stylesheet(stylesheet)
8 5
    expect(stylesheet).to_not be_nil
9

10
    # Name
11 5
    expect(stylesheet.name).to be_a(String)
12 5
    expect(stylesheet.name).to_not be_empty
13

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

20 5
  it "responds to #find_stylesheet" do
21 5
    expect(subject).to respond_to(:find_stylesheet)
22 5
    expect(subject.method(:find_stylesheet).arity).to eq 1
23
  end
24

25 5
  it "responds to #find_stylesheet!" do
26 5
    expect(subject).to respond_to(:find_stylesheet!)
27 5
    expect(subject.method(:find_stylesheet!).arity).to eq 1
28
  end
29

30 5
  describe "#find_stylesheet" do
31 5
    it "can find a stylesheet" do
32 5
      verify_stylesheet subject.find_stylesheet(valid_name)
33
    end
34

35 5
    it "cannot find an invalid stylesheet" do
36 5
      expect(subject.find_stylesheet(invalid_name)).to be_nil
37
    end
38
  end
39

40 5
  describe "#find_stylesheet!" do
41 5
    it "can find a stylesheet" do
42 5
      verify_stylesheet subject.find_stylesheet!(valid_name)
43
    end
44

45 5
    it "raises Roadie::CssNotFound on invalid stylesheets" do
46 5
      expect {
47 5
        subject.find_stylesheet!(invalid_name)
48 1
      }.to raise_error Roadie::CssNotFound, Regexp.new(Regexp.quote(invalid_name))
49
    end
50
  end
51
end

Read our documentation on viewing source code .

Loading