Displaying 20 results from an estimated 1000 matches similar to: "mock_model not stubbing model attribtues in view spec"
2012 Aug 03
1
Mock_model not recognizing act_as_mappable
I am using mock_model in my tests, and I encountered a situation where my
stub is failing. Here''s the scenario:
Controller:
@locations = Location.al(:bounds=>bounds)l
@locations.sort_by_distance_from([bounds.center.lat,bounds.center.lng])
Rspec:
@location = mock_model(Location)
Location.stub(:all).and_return([@location])
2011 Jan 30
5
Named routes problem... more rails than rspec
Howdy,
I have emailed before about the inconsistencies I''m spotting when using
named routes/resource, but I think I''ve narrowed down the issue. It would
seem this has nothing to do with rspec per se, but more with how routing
works with rails.
If you have an object instance, that isn''t saved and you attempt to generate
a path for that item, even though the item may
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 May 17
5
Help needed
Hi All,
I am new to rspec and it seems that I don''t understand some basics.
I need to have a XML import which should parse through XML data
and saves all that in various mysql tables. The XML part works just
fine and I can test this with rspec. However when I try to execute
it "should find country object for DE" do
I get an error. @user.country is a one-to-many relation in
2011 May 27
14
[rails] undefined method `model_name' for NilClass:Class
Never seen the error above before, code:
describe "edit action" do
it "edit action should render edit template" do
food = Food.create(:name=>''mooo'') #
Food.any_instance.stubs(:valid?).returns(true)
get :edit, :id => food.id
response.should render_template(:edit)
end
end
-------------- next part
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 Nov 04
18
Can I do foo.should (be_nil || be_empty) in rspec
Is there any way to do
foo.should (be_nil || be_empty)
in rspec.
Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081104/ee43c9c9/attachment.html>
2008 May 27
8
new --pattern option
Hello.
You''re saying that:
To get rspec to behave as it did before this change, use this:
--pattern "**/*.rb"
I tried like this (rspec 1.03) and it wasn''t same as before (rspec 1.08).
Now it also loads all other files in current directory and in all
subdirectories and not only from directory and subdirectories given to spec
as a parameter.
So, for example, I have
2008 Dec 02
11
Any plans for Before-feature or Before-all steps in Cucumber?
Hi
The code I''m working on now is a server daemon that talks to Twitter,
an RSS feed, and some web pages. I''ve got mock implementations of
Twitter and the web stuff, which I start and stop with
daemon_controller[1]. I do all the setup in a Before block, but this
makes the feature runs agonisingly slow due to the time waiting for
everything to restart. I''m
2007 Feb 16
6
some fun functionality for all your specs
I''ve found these two snippets of code useful and would love some feedback.
first, .should_have_valid_associations
usage:
context "A new Product" do
specify "should have valid associations" do
@product.should_have_valid_associations
end
end
code: (thanks to Wilson/Defiler for converting to rspec)
module Spec
module Expectations
module Should
2008 Apr 29
5
Sharing: dont_repeat_yourself plugin custom RSpec matcher
I wrote a Rails plugin which uses simian to look for duplicates lines in your
code and reports in html format, Textmate or Netbeans.
I wrote it using RSpec and I have included a RSpec custom matcher:
it { rails_application.
with_threshold_of_duplicate_lines(4).
should be_DRY }
If you use Autotest, your specs will fail the next time you do a nasty
copy-paste !!!
More details in
2007 Aug 19
4
describing a mock_model as being an instance
Is there a built-in way of describing a mock_model as being an instance, beyond
stubbing the eval("Object.methods - Object.new.methods") methods to throw
NoMethodErrors?
Edward
2009 Oct 14
14
spec-ing private methods?
On Wed, Oct 14, 2009 at 5:49 PM, Scott Taylor <scott at railsnewbie.com> wrote:
>
> On Oct 14, 2009, at 3:36 PM, Joaquin Rivera Padron wrote:
>
> hello there,
> how do you tipically spec private methods? The thing is ? have something
> like this:
>
> def some_method
> ?? complex_method + other_complex_methods
> end
>
> private
> def complex_method...
2008 May 18
2
Using Hash to mock classes that respond to :
Hi
I''ve been doing this a while now. If I have a class that responds to :
[], and all I''m interested in stubbing is that method, then instead of
using a mock I just create a hash. (Similarly, you could create an
array when you are testing an Enumerable object.)
Example from code I just worked on, where uses MigrationGraph#[] looks
up graph vertices by name:
2007 Aug 30
7
mock_model in spec/lib
Has anyone else run into a problem with trying to use mock_model in spec/lib ?
For some reason, I can take the same spec, put it in spec/models, have it run
fine, but put it in spec/lib, and have it complain about not being able to find
#mock_model
Thanks,
Edward
2007 Dec 05
9
Does mock_model''s :null_object option work?
Please understand in the following that I am making relatively minor changes to legacy (non-TDD/BDD) code in Substruct and don''t have 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
2007 Oct 06
4
spec''ing views, mock_model associations
I writing a spec that returns the count of how many players in a game:
it "should how many players in a link to all players" do
render :partial =>"games/game", :object => @game
response.should have_tag(''a'',"(2) Players")
end
I''m not sure how to do the mock model, I think it would be done two ways but
unsure of the syntax:
1: add
2007 Oct 12
3
Strange mock_model behaviour with ActiveResource model
Hi,
I have two models in an app that inherit from ActiveResource::Base.
The scaffold controller tests for one of the models works fine, but
the other one dies when calling mock_model in the "handling GET
/fa_codes" spec:
Specifically, the call to mock model here:
before do
@fa_code = mock_model(FaCode)
FaCode.stub!(:find).and_return([@fa_code])
end
generates this failure:
2007 Sep 29
1
mock_model named spaces not working
I have a namespace called saltmines
The following will fail the spec
@player = mock_model(Saltmines::Player)
1)
ActionView::TemplateError in ''/saltmines/players/index.rhtml should render
list of saltmines/players''
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
On line #9 of
2008 May 23
3
RailsExampleGroup
So I have a describe which is a subclass of RailsExampleGroup. I inserted
some data into my database, and reconnect! my connection. Before reconnect,
finding the data I just created is fine. The data cannot be found, after
reconnection, the data is gone. It''s not in the database. It looks to me the
data is not actually inserted into the DB at all, just somehow buffered
somewhere. Would