spec/forgery_spec.rb in forgery-0.2.2 vs spec/forgery_spec.rb in forgery-0.3.0

- old
+ new

@@ -1,6 +1,7 @@ require File.dirname(__FILE__) + '/spec_helper' +require 'pathname' describe Forgery do it "should load a dictionary when it is requested" do Forgery.dictionaries.reset! @@ -20,23 +21,49 @@ Forgery.formats.should be_loaded(:phone) end it "should accept a symbol and return the appropriate forgery class" do - Forgery(:address).should == AddressForgery - Forgery(:basic).should == BasicForgery - Forgery(:internet).should == InternetForgery + Forgery(:address).should == Forgery::Address + Forgery(:basic).should == Forgery::Basic + Forgery(:internet).should == Forgery::Internet end it "should accept two symbols, finding the right class and calling the appropriate method" do - AddressForgery.should_receive(:street_name) + Forgery::Address.should_receive(:street_name) Forgery(:address, :street_name) - NameForgery.should_receive(:full_name) + Forgery::Name.should_receive(:full_name) Forgery(:name, :full_name) end it "should accept two symbols and arguments, passing them along to the appropriate method" do - LoremIpsumForgery.should_receive(:text).with(:sentences, 2) + Forgery::LoremIpsum.should_receive(:text).with(:sentences, 2) Forgery(:lorem_ipsum, :text, :sentences, 2) + end + + it "should return the rails root path if RAILS_ROOT is defined" do + RAILS_ROOT = '/path/from/rails/root/const' + Forgery.rails_root.should == '/path/from/rails/root/const' + Object.instance_eval { remove_const(:RAILS_ROOT) } + end + + it "should return the rails root path as a string if Rails.root is defined" do + Rails = Object.new + Rails.stub!(:root).and_return(Pathname.new('/path/from/rails/dot/root')) + Forgery.rails_root.should == '/path/from/rails/dot/root' + Object.instance_eval { remove_const(:Rails) } + end + + it "should return nil when RAILS_ROOT and Rails.root are not defined" do + Forgery.rails_root.should be_nil + end + + it "should not be a rails environment when there is not a rails_root" do + Forgery.rails?.should be_false + end + + it "should be a rails environment when there is a rails_root" do + Forgery.stub!(:rails?).and_return(true) + Forgery.rails?.should be_true end end