Displaying 18 results from an estimated 18 matches for "null_object".
2007 Dec 05
9
Does mock_model''s :null_object option work?
...ave the time to refactor nicely right now. I''m just trying to get past the untested/un-speced cruft quickly to write the spec for my new code, so I''m looking for expediency over prettiness.
I''m specifying
before( :each ) do
@order_address = mock_model( OrderAddress, :null_object => TRUE )
end
but finding that unstubbed/unmocked method calls on @order_address still throw error messages like:
Mock ''OrderAddress_1026'' received unexpected message :first_name with (no args)
so I''m starting to wonder whether the :null_object option is doing anyth...
2010 May 27
3
as_null_object
Given that RSpec has the following methods to create test doubles ...
double(:my_test_double)
mock(:my_mock_object)
stub(:my_stub)
Is there a way to/ plans to introduce a similar syntax for null
objects?
null_object(:my_null_object)
Instead of mock(:bar, :is_null_object => true) or
mock(:foo).as_null_object
I think this would be cleaner, what do you think?
2008 Nov 03
1
stub! and null_object
...do @user.stub!(:record_action) and that would
return a null object that didn''t care what we did to it.
However, possibly due to my own ignorance, I''m having to do something
a lot more ugly, like this:
@user.stub!(:record_action).and_return(mock(''blah'',:null_object
=> true))
Can anyone beautify this a bit more?
cheers,
Matt
2007 Aug 14
4
Stubbing all methods
Mocha''s mock/stub framework has the ability to stub all methods on a
mock given. Does RSpec''s mocking framework have this ability? And
if not, is there some reason it shouldn''t be implemeneted?
Regards,
Scott
2006 Jul 24
6
Mocking causes empty specification blocks
I''ve found myself mocking out a published api in my set-up method.
This has led to some contexts having a large set-up and empty
specifications. As the mocks get auto-verified, the specification
blocks have nothing to do but serve as documentation. Does this sound
bad?
Chris
2008 Jun 04
2
Mock with an attributes that has state
...ge helper function should do is increment the
quantity of the merged OrderItems. Below @order_item1 and @order_item4
would be merged into one item with a quantity of 2.
Here are my OrderItems mocks:
@order_item1 = mock_model(OrderItem, :valid? => true, :product_id => 1,
:cost => 1, :null_object => true)
@order_item2 = mock_model(OrderItem, :valid? => true, :product_id => 1,
:cost => 2, :null_object => true)
@order_item3 = mock_model(OrderItem, :valid? => true, :product_id => 2,
:cost => 1, :null_object => true)
@order_item4 = mock_model(OrderItem,...
2007 Jan 30
0
nil object in mocks
...when passing mock objects
into rich views. Either I have to obscure my specs by stubbing every
method the view would call on my object, or I have to resort to
trickery like stubbing ActionController#render, which is also less
than ideal.
The solution I''ve some up with is a variant on the :null_object option
that can be passed to the mock factory. Null objects return themselves
from any unstubbed method call. The option I''ve added changes that
return value to nil, which doesn''t play so well with method chaining,
but does work nicely in most views.
The question for you all is:...
2008 May 26
7
Mocking Models in Controller Specs...
I find myself doing this kind of thing a lot in Controller Specs:
@vacancy = mock_model(Vacancy)
@vacancy.stub!(:reference)
@vacancy.stub!(:title)
@vacancy.stub!(:created_at)
@vacancy.stub!(:updated_at)
@vacancy.stub!(:body)
@vacancy.stub!(:contract)
@vacancy.stub!(:location)
@vacancy.stub!(:salary)
@vacancy.stub!(:benefits)
2008 Jul 25
21
Problems with mock assigned to a constant
Hi all,
Initially I thought this was a bug in the built-in mocking framework(and it
still may be), but I better hash it out on the mailing list before I
file/reopen the ticket:
http://rspec.lighthouseapp.com/projects/5645/tickets/478-mocks-on-constants#ticket-478-6
I thought my example illustrated my problem, but obviously I was passing the
wrong arguments to the mock. I revised my example to
2007 May 08
4
help with rspec''ing controller
...w).with(:params).and_return(@product)
post ''create'', :product => :params
end
end
describe "Create with a valid product and authenticated user with
everything in setup" do
controller_name :product
setup do
@product= mock(:product, :null_object => true)
Product.stub!(:new).and_return(@product)
@product.should_receive(:save!).and_return(true)
#mock_user_authentication(true)
post :create, :product => {''name'' => ''a new product'',
''description'...
2007 Nov 28
6
Newbie question
I installed Rspec and am getting the following failure:
$ sudo gem install rspec
Successfully installed rspec-1.0.8
Installing ri documentation for rspec-1.0.8...
Installing RDoc documentation for rspec-1.0.8...
$ spec -v
RSpec-1.0.8 (r2338) - BDD for Ruby
http://rspec.rubyforge.org/
$ cat acct.rb
describe Account, " when first created" do
it "should have a balance of $0"
2007 Feb 07
5
Mocking ActiveResource
I want to use ActiveResource in my app. Instead of hitting server
though, I want it to load from a file when I call find. Any clue how
I do that?
Pat
2007 Oct 31
16
Am I missing something with Heckle?
Hi
I can''t get heckle working. In fact, I''ve built an example so simple
that it either shows a bug, or I am being really, REALLY stupid.
Heckle does not appear to support RSpec directly, so I''m trying to use
spec --heckle (RSpec trunk as of 10 mins ago, Heckle 1.4.1). I''ve
constructed this pair of sample files:
18> ~/Desktop/heckle_test % cat
2007 Jun 24
6
mocking errors
What is the correct way to mock out the errors on a Rails model?
I''m assuming i need to say
@mock_thing = mock_model(Thing)
@mock_thing_errors = mock("errors")
@mock_thing_errors.should_receive(:full_messages).and_return("An error")
@mock_thing.should_receive(:errors).and_return(@mock_thing_errors)
Just wanted to check the best practice on this kind of thing and how
2006 Jul 24
2
Creating a ''default'' mock
Am I correct in thinking that it''s not currently possible to have a
method that creates a ''standard'' mock (i.e. a mock that has defaults
useful in all contexts)?
I''ve tried with the mock method and also by manually creating new Mock
instances. I get failures when setting up expectations (undefined
method ''receive'' for proc).
Chris
2007 Nov 20
2
confirming that a model instance was correctly created from POST params
...end
I am adding to the OrderAddress model the concept of whether an address is a business address (as opposed to a home/residential address):
describe OrderHelper do
it ''should record the fact that the address is a business address'' do
1 order = mock_model( Order, :null_object => TRUE )
2 order.stub!( :valid? ).and_return( TRUE )
3 Order.stub!( :new ).and_return( order )
4 order.stub!( :order_number= )
5 order.stub!( :save! )
6
7 params[:order_user] = Hash.new
8 params[:order_user][:email_address] = ...
2008 Sep 24
19
How to define request.domain in when testing
Hi,
My application relies on request.domain for doing its job. The problem I
am encountering, is that when running tests, request.domain returns
"test.host", how can I change that so that it returns "mysite.com"?
Thanks in advance.
--
Posted via http://www.ruby-forum.com/.
2008 Jun 28
19
Stopping example execution?
Hello, I''m wondering If I am missing something here when creating an example that sets an expecation at the top or beginning of an action but requires you to stub / mock everything that follows.
Example:
I want to test that a certain controller is running a before_filter...thats easy:
- controller.should_receive(:require_user)
- do_get
But now i''ve got to mock / stub