Sha256: 483a5dafe635b23247316982ca04a745e5b1250c71bc2682b8cbd312e80c57ff

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

RSpec.shared_examples "an element" do
  let(:resolver) { HungryForm::Resolver.new() }
  
  let(:group) { HungryForm::Group.new(:group, nil, resolver, {}) {} }

  let(:element) { described_class.new(:element_name, group, resolver, element_options) {} }

  describe "#visible?" do
    it "should be visible" do
      expect(element.visible?).to eq true
    end

    it "should not be visible" do
      element_options[:visible] = false
      expect(element.visible?).to eq false
    end

    context "when dependency is present" do
      it "should not be visible" do
        element_options[:dependency] = '{"EQ": ["0", "1"]}'
        expect(element.visible?).to eq false
      end

      it "should be visible" do
        element_options[:dependency] = '{"EQ": ["1", "1"]}'
        expect(element.visible?).to eq true
      end
    end
  end

  describe "#label" do
    it "should have a humanized label based on element's name" do
      expect(element.label).to eq "Element name"
    end

    it "should have a label defined in options" do
      element_options[:label] = "Special Label"
      expect(element.label).to eq "Special Label"
    end
  end

  describe "#method_missing" do
    it "should return existing param" do
      element_options[:html_param] = "param"
      expect(element.html_param).to eq "param"
    end

    it "should check whether param exists" do
      element_options[:html_param] = "param"
      expect(element.html_param?).to eq true
      expect(element.other_html_param?).to eq false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hungryform-0.0.2 spec/support/shared_element.rb