Sha256: 01b6e1e773f8c22b235aa3d332ebaed9b21af535e99e7219fbc70858926fceed

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 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" => "programmer"
      } 
    } 
  end

  subject do
    HungryForm::Form.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 
        select_field :occupation, :options => {"programmer" => "Programmer", "other" => "Other"}
        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::Form.new() {} }

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

  describe "#to_json" do
    it "should create a json string from the form objects" do
      hash = JSON.parse(subject.to_json)
      expect(hash["pages"].size).to eq 2
      expect(hash["pages"].first["elements"].size).to eq 2
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hungryform-0.0.4 spec/form_spec.rb