Sha256: b8dd9a27b45a07f61fdfc02ed8ae5d7539af850b183e657c51e898de998863de

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

RSpec.shared_examples "an element" do
  let(:resolver) { HungryForm::Resolver.new() }
  
  let(:group) { HungryForm::Elements::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

  describe "#to_hash" do
    it "should include visible, dependency, name and label" do
      element_options[:dependency] = '{"EQ": [1, 1]}'
      element_options[:name] = 'name'
      expect(element.to_hash).to include(:visible, :dependency, :name, :label)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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