require "spec_helper" describe Form::Component::Label do describe "#text" do let(:form) { mock(base_name: nil) } subject { described_class.new(form, :email) } context "with simple name" do it "returns specified text" do subject.options[:text] = "E-mail address" subject.text.should eql("E-mail address") end it "returns text for full scope" do i18n :en, {form: { labels: {email: "E-mail"} }} subject.text.should eql("E-mail") end it "returns humanized text" do subject.text.should eql("Email") end end context "with composed name" do before { form.stub base_name: %w[user profile] } it "returns specified text" do subject.options[:text] = "E-mail address" subject.text.should eql("E-mail address") end it "returns text for full scope" do i18n :en, {form: { labels: {user: {profile: {email: "E-mail"}}} }} subject.text.should eql("E-mail") end it "returns text for root scope" do i18n :en, {form: { labels: {email: "E-mail"} }} subject.text.should eql("E-mail") end it "returns humanized text" do subject.text.should eql("Email") end end end end