Permalink
Browse files

Clean up stubbing of Rails in specs

  • Loading branch information...
1 parent 70bde96 commit 90a4faad3d5021e59657d20f72c0504350d61b4e @bowsersenior bowsersenior committed Jan 5, 2012
Showing with 39 additions and 29 deletions.
  1. +1 −1 spec/monkeypatches/rails_helper_spec.rb
  2. +38 −28 spec/yacht/rails_spec.rb
@@ -17,7 +17,7 @@ class DummyClass
}
before do
- Rails = stub('Rails')
+ Kernel.stub('Rails')
require "monkeypatches/rails_helper"
@@ -2,46 +2,56 @@
require "yacht/rails"
describe Yacht::Rails do
- subject {
- @yacht_dir = "/path/to/rails/config/yacht"
-
- class SomeClass
- class << self
- attr_accessor :environment, :dir
- def all
- end
+ class SomeClass
+ class << self
+ attr_accessor :environment, :dir
+ def all
end
end
+ end
- SomeClass.stub(:rails_env).and_return(:awesome)
- SomeClass.stub(:rails_default_yacht_dir).and_return(@yacht_dir)
+ subject { SomeClass }
- class SomeClass
- include Yacht::Rails
+ describe "when Rails does not exist" do
+ it "should raise an error" do
+ expect{
+ class SomeClass
+ include Yacht::Rails
+ end
+ }.to raise_error ('Rails is not defined!')
end
- }
-
- before do
- @yacht_dir = "/path/to/rails/config/yacht"
end
- describe :environment do
- it "uses the current rails environment by default" do
- subject.environment.should == :awesome
+ describe "when Rails exists" do
+ before do
+ @yacht_dir = "/path/to/rails/config/yacht"
+
+ SomeClass.stub(:rails_env).and_return(:awesome)
+ SomeClass.stub(:rails_default_yacht_dir).and_return(@yacht_dir)
+
+ class SomeClass
+ include Yacht::Rails
+ end
end
- end
- describe :dir do
- it "uses config/yacht by default" do
- subject.dir.should == @yacht_dir
+ describe :environment do
+ it "uses the current rails environment by default" do
+ subject.environment.should == :awesome
+ end
end
- end
- describe :all_with_rails_env do
- it "adds the current Rails environment to super" do
- subject.stub(:all_without_rails_env).and_return(:foo => :bar)
+ describe :dir do
+ it "uses config/yacht by default" do
+ subject.dir.should == @yacht_dir
+ end
+ end
+
+ describe :all_with_rails_env do
+ it "adds the current Rails environment to super" do
+ subject.stub(:all_without_rails_env).and_return(:foo => :bar)
- subject.all_with_rails_env.should == {:foo => :bar, 'rails_env' => :awesome}
+ subject.all_with_rails_env.should == {:foo => :bar, 'rails_env' => :awesome}
+ end
end
end
end

0 comments on commit 90a4faa

Please sign in to comment.