Displaying 20 results from an estimated 10000 matches similar to: "Is there an equivalent to anything() for Hash parameters?"
2008 Mar 05
14
ActiveRecord, spec''ing find has right :order parameter
I''m wanting to write a spec that a model is applying an :order option
to a find call, but I don''t want to completely specify all of the find
parameters.
So I want to write something like this, say in a controller spec
User.should_receive(:find).with(:all, hash_with_at_least(:order =>
''user.name ASC''))
get ''index'', :sort =>
2008 Aug 06
3
hash_excluding/hash_only?
I know there is a hash_including, which is quite useful. Are there by
chance any matchers for ensuring a hash includes only the specified
values, or that it doesn''t have certain values?
Thanks,
Steve
2007 Oct 20
14
Problems with form_for and partials
i''m having problem with a form_for situation where i''m trying to DRY
out the repeated parts of my forms and put them in common/form and
render the form elements via another partial in controller_name/_form.
Here''s the first form
# app/views/common/form
<% form_for ... do |f| -%>
<%= render :partial => "params[:controller]/form", :object => f
2008 Nov 13
6
.with(:anything) issue
Hi,
I''m using a expectation like this :
repository.should_receive(:add_gem).with("test.txt", :anything)
When I run my spec, it fails with the following message :
Spec::Mocks::MockExpectationError in ''MiniGemServer should add a new gem to
the repository after it has been uploaded''
#<MiniGemServer::Repository:0xb11164> expected :add_gem with
2007 May 15
3
nested blocks
Hello,
Does anyone have an explanation for why the following code results in
the error that follows? I also would value any criticisms of my
approach (i.e., defining it_should_populate_collections). Thanks
-Chris
#Code
def it_should_populate_collections(condition=nil)
it "should populate any necessary collections #{condition}" do
[*@collections_to_populate].each do
2007 Jul 09
12
Mocking User.find( :all, :limit => 10 )
Hi,
I''m trying to setup a mock for my controller test but I can''t get it to
recognise the mock.
I use
it "should find all users" do
User.should_receive(:find).with( :all, :limit => 10
).and_return([@user])
do_get
end
and in the controller
@users = User.find(:all, :limit => 10 )
But this does not work. It gives me
User expected :find with (:all)
2007 Jun 19
5
Problems translating should_render from 0.8.2 to 1.0.5
<font size="2">I''m working on a large Rails site and we want to move from RSpec 0.8.2 to the latest and greatest. So we ran the translator and yet we''re having a lot of trouble translating should_render.<br><br>I found this on the web:<br><br>We will NOT be supporting the following in the new syntax:<br>
2007 May 10
5
Shared behavior and_raise problem, and site aestetics
Hello,
Is anyone else having trouble with the and_raise method on mocks,
with respect to shared behaviors? If I do the following instead:
foo.should_receive(:bar).and_return { raise }
everything seems to work. I have been supplying no arguments to
and_raise, by the way.
Also, you may want to make the background in the code examples on the
home page a little lighter. I am hardly able to
2007 Oct 05
13
spec''ing view render partial collection, local variable not found
I''m trying to spec out a render partial collection but I get the following
error
2)
NoMethodError in ''/games/_game.rhtml should show game name''
undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c>
/Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in
`matches?''
2008 Jun 07
3
Match render :nothing
Hello guys,
Is there any way to match a render :nothing?
I coudn''t find any way to do this so i''ve just changed my controllers
to do a "head :ok", but it would be nice to know if there is any other
way :)
--
Maur?cio Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en)
Jo?o Pessoa, PB, +55 83 8867-7208
2010 Jun 20
10
RSpec 2 view example: render_template
On http://github.com/rspec/rspec-rails under "View specs" there''s an
example
describe "events/index.html.erb" do
it "renders _event partial for each event" do
assign(:events, [stub_model(Event), stub_model(Event)])
render
view.should render_template(:partial => "_event", :count => 2)
end
end
Is this indeed correct? From the
2007 Jun 03
3
should_receive.again
Hi,
It appears that if I have 2 should_receives in a row, the latest one
overrides the previous one(s).
If there isn''t one, could we add a way to accumulate them, such as
@thing.should_receive(:method).and_return(@value)
@thing.should_receive(:method).again.and_return(@value)
@thing.should_receive(:method).again.and_return(@value)
would be equivalent to
2009 Apr 22
15
Why RSpec?
I like Shoulda. Sometimes I like plain old Test::Unit. Cucumber
gives me a different thought process.
I''d just like to hear some thoughts on why RSpec? What does it buy me
that I can''t get with Shoulda? I just can''t seem to think in RSpec.
Where is there a good example of RSpec tests that will help me grasp
the right path?
Thanks!
--
Amos King
2007 Oct 09
23
Testing layouts with RSpec on Rails
Hey guys,
Does anyone have any wisdom to share on the subject of speccing Rails
layouts?
Most of it''s plain old view specs stuff, but are there sensible ways
to verify things like the yield call? (Mocking doesn''t catch that)
Thanks,
Matt
--
Matt Patterson | Design & Code
<matt at reprocessed org> | http://www.reprocessed.org/
2006 Oct 23
6
overriding mock expectations
There is one annoyance I''m encountering with the Mock API in rSpec.
Overall it works well, as far as dynamic mocks go ;)... but there''s
this one thing... It doesn''t allow overriding of expectations.
example:
m = mock("blah")
m.should_receive(:one).any_number_of_times().and_return(1)
m.should_receive(:one).and_return(1)
The second call to should_receive
2007 Nov 01
2
Writing controller specs
One thing that is bothering me about my controller specs is that
sometimes I end up with a number of examples that are the same except
for the example name.
The reason that this happens is that I''ve expressed all the expected
behavior with should_receive. While this does more or less work as
intended it doesn''t feel right.
As an example, let''s say I''m writing
2011 Jul 27
3
Rspec with ActionMailer and .deliver
I''m in the process of migrating from Rails 2 with rspec 1 to Rails 3 with
rspec 2, the process has been going pretty well, however, today I came
across an issue that I wanted to share.
I have a controller that sends out an email through a mailer.
Rails 2
code: CurriculumCommentMailer.deliver_comment_update(@curriculum_comment,
"created")
Rails 3 code:
2007 Aug 17
4
should_receive, used in the wrong place?
What do you guys think of this: if someone calls should_receive
outside of an "it" block, it warns you.
before(:each) do
@foo = Foo.new
@foo.should_receive(:monkeys)
end
would warn you that you''re setting an expectation in the wrong place,
and that "stub" is correct when setting up objects.
Opinions?
courtenay
2008 Mar 08
3
should_receive(:foo).with(any_object)
Hey,
I just ran into a situation where I would like to expect a method call
with an argument I know and another one, which is a random number. I
think mocking up the rand method is somehow ugly so I thought maybe
this is the first time where I can take something from Java to Ruby ;)
Java''s EasyMock mocking library knows things like "anyObject()" and
"anyInteger()" in
2008 Jan 13
2
should_receive twice and arguments
Hi all, I have a method calling Klass.create! two times with different
arguments (this happens in a class reponsable for reading in a csv file)
I want to test those like this:
in one test: Klass.should_receive(:create!).with(:name => "foo").once
in another: Klass.should_receive(:create!).with(:name => "foo2").once
This doesn''t work because the