Sha256: 6803d299ddc78c4cbeb7cf8051b2709ea2b7d90c479850a0cc2075b1ff2003a4

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require "spec_helper"

describe HungryForm do
  let(:options) do
    {
      :params => {
        "first_first_name" => "John", 
        "first_last_name" => "Doe", 
        "second_email" => "john.doe@yahoo.com", 
        "third_occupation" => "Software developer"
      } 
    } 
  end

  subject(:form) do
    HungryForm.new(options) do
      page :first do
        text_field :first_name
        text_field :last_name
      end
      page :second, visible: false do 
        text_field :email
      end
      page :third do 
        text_field :occupation
        group :employment_history do
          html :before, value: "Employment history over the last 5 years"
          text_field :history, value: "Default value"
        end
      end
    end 
  end

  describe ".new" do
    it "should contain pages" do
      expect(subject.pages.size).to eq 2
    end
  end

  describe "#page" do 
    subject(:form) { HungryForm.new() {} }

    it "should contain a page" do
      form.page(:page_name, {}) {}
      expect(form.pages.first.class).to eq HungryForm::Page
    end
  end

  describe "#to_json" do
    it "should create a json string from the form objects" do
      form_elements_hash = options[:params].merge({"third_employment_history_history" => "Default value"})
      expect(form.to_json).to eq(JSON.generate(form_elements_hash))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hungryform-0.0.2 spec/hungryform_spec.rb