Displaying 20 results from an estimated 20000 matches similar to: "question"
2010 Aug 18
2
dynamic tests possible?
Sorry if this is a newbie question, but here goes.
I was wondering if the following is somehow possible:
for file in Dir[''*.bmp'']
it "should be able to parse #{file}" do
p file
# test this file
end
end
Currently rspec seems to evaluate the blocks after the fact, leading
to "file" always being the last file in the list.
I was unsure
2007 May 20
9
How to test for exceptions
Hi folks,
I''m in the process of converting a Test::Unit functional test to RSpec, but I''ve run into a slight problem. I tried looking through the documentation but I still don''t know what I missed.
Thanks in advance,
Blake
describe VenuesController, "on update" do
before(:each) do
@venue = mock("venue")
2006 Dec 21
3
Speccing private class methods
Hi
How can I specify that a private method of a class gets called? If
you run the code below, only spec (1) passes. Spec (2) is what I
found causing problems in my code, and class (3) is my failed attempt
to work around it. (3 really puzzles me - why is a private class
method not accessible via send?)
Another problem is that stub! makes public methods, which changes the
behaviour of
2007 Oct 20
1
Using unit_record and rspec (previously "Keeping unit tests from hitting the DB")
Back in August David Chelimsky wrote:
"FYI - I tried using the unit_record gem and there are some changes
required in rspec to make it work, but they are trivial and it works
great. The only trick is that the prevention of DB access is global
per process, so you''d have to separate examples that hit the DB from
those that don''t into two separate suites. I''ll explore
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 Aug 07
4
Problems with raising errors on a mocked object
I''m trying to mock a object to raise a certain error. By doing so I
get a ArgumentError on ActiveRecord''s save! method:
http://pastie.caboo.se/85628
I''ve tried to debug it but just can''t seem to find what I''m doing
wrong. Any help is greatly appreciated.
Cheers,
Eivind Uggedal
2011 Aug 10
5
ControllerExampleGroup.bypass_rescue
As best I can tell, bypass_rescue from rspec-rails-1 is no longer part of rspec-rails, ''> 2''. I had been using it on occasion for things like:
describe CorrespondencesController do
...
describe ''#show'' do
it "should raise an AuthorizationError if current user is not the correspondent " do
bypass_rescue
...
expect { do_get
2007 Dec 12
3
undefined method: controller_name
With rspec 1.0.8 I have a spec in the directory:
spec/units/controllers/application_controller_spec.rb
require File.dirname(__FILE__) + ''/../../spec_helper''
class DummyController < ApplicationController
def index
raise "Prevent index from rendering"
end
end
describe ApplicationController, "Handling errors in production",
:behaviour_type =>
2010 Nov 02
7
Testing attr_accessible (and/or attr_protected)
I''ve been puzzling over how to test that attr_accessible has been set
for the correct columns; but the tests I''ve come up with so far seem
to fail to fail when I expect. I came across this old message from
this list:
http://www.mail-archive.com/rspec-users at rubyforge.org/msg01570.html
Which seemed like a plausible example, but my attempt (modeled on the
example)
2006 Nov 22
3
Controller Isolation
Hi,
I have a project that I had running under rspec 0.6.x and recently upgraded
to 0.7.2.
I am trying to isolate my controllers from the database as I go through and
change all the specs to run under 0.7.2.
I am having a problem where I need to make the create! method return the
mocked object as well as raise RecordInvalid exception. Is this at all
possible?
I use the rescue statement in my
2010 Sep 23
2
rspec runner setting $KCODE considered harmful?
I ran across a problem today in which some code ran fine in regular
operation but failed in a test case. I scratched my head and thought "why
would running from within the test harness change the behavior of my code?"
Clearly it was the Heisenberg uncertainty principle in action! :)
I discovered the root cause was that the rspec runner is setting the magical
ruby global, $KCODE, to
2007 Jul 06
1
Edge, link_to and mocks
Hi All,
Anyone noticed that using the newer link_to syntax in edge currently
fails with mocked objects in view specs or helpers.
eg. if you have something like the following in your view (or
equivalent in a helper):
<%= link_to @dog.name, @dog %>
as opposed to the current 1.2 syntax:
<%= link_to @dog.name, dog_path(@dog) %>
Using a mock_model as the ''dog''
2007 Apr 17
8
Verifying that a block calls a method
I have something like the following:
def my_fun
my_fun2 do
raise Error
end
end
I know that I can verify that the method receives my_fun2. How can I
mock/stub out the example to verify that it calls raise Error?
Scott
2009 Apr 16
6
Cucumber - step negating another expecting step
On 16 Apr 2009, at 11:22, Joaquin Rivera Padron wrote:
> at the moment I do it this way, hiding the complexity out of the
> steps:
>
> Then /^I should see the people search form$/ do
> people_search_form_exists
> end
>
> Then /^I should not see the people search form$/ do
> people_search_form_exists "not"
> end
>
> and then the method:
>
>
2007 Oct 23
9
Running rails specs outside of the normal project tree
I want to create a spec/regressions directory with various
regressions (for my rails project). I tried the following:
describe LoginController, "regression for user creation when
steves_sister does not exist", :behavior_type => :controller do
controller_name :login
before :each do
@params = {
"commit"=>"Create Account",
2008 Mar 19
2
rescue
Hi, whats the correct way to spec a rescue? This will raise it but
doesnt test my code''s response
# controller
def edit
@foo = Foo.find(params[:id])
rescue
flash[:notice] = "Unknown foo #{params[:id]}"
redirect_to foos_path
end
# spec
it "should flash error if not found" do
Foo.should_receive(:find).and_raise
get :edit, :id
2006 Dec 21
1
heres how to get color output in rspec_autotest with rspec 0.7.5
In case anyone else is trying to make this work, here is what I did
(Before 0.7.4 I had patched the regex in zentest redgreen, but that
is not used any more)
To use directly, it is very simple. In rspec_autotest/lib/
rspec_autotest.rb, add a -c to the spec_command in the initializer
function:
@spec_command = "spec -c --diff unified"
This won''t help however if you want
2011 Mar 04
5
How to intercept an instance method from StdLib (1.9.2)
Hi,
I''m struggling with something that seems to be simple, and I''ve not
had any joy following the RSpec books suggestions (p. 187).
I''d like to test that a method raises and error when a file is not found.
I''ve tried adding this in my example just before I call my method, but
it never seems to get invoked.
Pathname.stub(:exist?).and_return(false)
The whole
2008 Dec 09
3
a custom progress bar formatter
I''ve always been a little bit bemused by the default ruby test/unit and
rspec output. Basically, what I want is a progress bar and that any
errors and warnings be displayed immediately. I also want warnings to be
printed for slow specs. When using color, I want the entire progress bar
printed in green if everything is good, yellow if there has been a
warning, and red if there has been an
2007 Sep 13
2
Failing to raise an exception in a stub
I''ve come across rather strange behaviour when trying to raise an
exception in a stubbed method.
I''m speccing the behaviour of a Rails create action, where I''m using
save! to catch failed saves. In the case of working save, I''m using
the following stub:
@client.stub!(:save!).and_return(true)
which works fine.
However, in the negative case,