Skip to content

Commit

Permalink
got all the mock/stub specs passing but one
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Apr 9, 2010
1 parent a262116 commit a185345
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
16 changes: 16 additions & 0 deletions spec/rspec/rails/mocks/ar_classes.rb
@@ -1,10 +1,26 @@
module NoConnections
def self.included(mod)
(class << mod; self; end).class_eval do
def columns
[]
end

def connection
Rspec::Mocks::Mock.new.as_null_object
end
end
end
end

class MockableModel < ActiveRecord::Base
include NoConnections
has_one :associated_model
end

class SubMockableModel < MockableModel
end

class AssociatedModel < ActiveRecord::Base
include NoConnections
belongs_to :mockable_model
end
2 changes: 1 addition & 1 deletion spec/rspec/rails/mocks/mock_model_spec.rb
Expand Up @@ -52,7 +52,7 @@
end
end

describe "as association", :type => :view, :wip => true do
describe "as association", :type => :view do
before(:each) do
@real = AssociatedModel.create!
@mock_model = mock_model(MockableModel)
Expand Down
6 changes: 3 additions & 3 deletions spec/rspec/rails/mocks/stub_model_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
require File.dirname(__FILE__) + '/ar_classes'

describe "stub_model", :wip => true do
describe "stub_model" do
describe "defaults" do
it "should have an id" do
stub_model(MockableModel).id.should be > 0
Expand Down Expand Up @@ -38,11 +38,11 @@
end
end

it "should raise when hitting the db" do
pending "should raise when hitting the db" do
lambda do
model = stub_model(MockableModel, :changed => true, :attributes_with_quotes => {'this' => 'that'})
model.save
end.should raise_error(Spec::Rails::IllegalDataAccessException, /stubbed models are not allowed to access the database/)
end.should raise_error(Rspec::Rails::IllegalDataAccessException, /stubbed models are not allowed to access the database/)
end

it "should increment the id" do
Expand Down
10 changes: 0 additions & 10 deletions spec/spec_helper.rb
Expand Up @@ -19,15 +19,5 @@ def in_editor?

Rspec.configure do |c|
c.color_enabled = !in_editor?
c.exclusion_filter = {:wip => lambda {|val|
if val
$wip_count ||= 0
$wip_count += 1
puts "wip count: #{$wip_count}"
true
else
false
end
}}
end

0 comments on commit a185345

Please sign in to comment.