I have a test which needs to check if a block given to a method is being called.
block = lambda {
#some stuff
}
block.should_receive(:call)
get_data_with_timeout(1, &block)
def get_data_with_timeout(timeout)
begin
timeout(timeout) {
data = get_data
yield data #do stuff
}
rescue Tim...
What I want is a way of not having to 'require' the class under test in each spec file.
So hoping there is a means of setting the root of the source code under test and rspec automatically mapping my tests, or any other means of automatically mapping specs to ruby files.
In Rspec for rails this happens magically, but this is not a ra...
I'm using RR for mocking and stubbing in RSpec, and I've run across a situation where I'd like to stub a method from a super class of a controller that sets some instance variables. I can work out how to stub the method call and if I debug I can see that my stubbed block is called, but I cannot get the instance variables in the block to ...
I have Rspec + Shoulda + FactoryGirl and I am receiving the following error when attempting to call Shoulda's have_many or belong_to methods. All Shoulda methods used in the "validations" group work fine:
> NoMethodError in 'A Project
> associations should When you call a
> matcher in an example without a
> String, like this:
>
> s...
Hi,
Is Rspec ruby/rails specific? Is it possible to use it as a test framework for C/C++ program?
...
Hi guys, I'm using rspec to test a code that may fail depending on the change of a site structure (the external influence I mentioned). I would like to write an example that involves "should raise an error" but I'm not sure if rspec is the right tool to test code in such situations. Could someone point me in some direction?
Thanks in a...
Is there any way to have RSpec continue processing specifications after an exception is raised?
This is what my spec task looks like:
SPEC_PATTERN = "spec/**/*_spec.rb"
Spec::Rake::SpecTask.new() do |t|
t.spec_files = FileList[SPEC_PATTERN]
t.verbose = true
t.spec_opts = ["--format", "html:spec/spec_report.html"]
t.fail_on_erro...
Hi, I'm new to rails and I'm trying to test a controller with rspec. My first test is when the show action is invoked, it should lookup a Category by url.
The problem is when I add the stubbing code, I get the following error:
undefined method `find' for #
my test looks like this:
require 'spec_helper'
describe CategoriesController ...
Hi everyone,
I'm trying to set up teamcity 5.0.2 to run my rails projects specs (just rake spec)
My setup is:
local git repo
rails app root in
side it (git_root/site_root)
my rake runner settings are:
path to rakefile: site_root/Rakefile
working directory: site_root
rake tasks: spec
attached reporters: rspec
everything else is ...
I'm trying to expect an error in an rspec test.
lambda {Participant.create!({:user_id => three.id, :match_id => match.id, :team => 1})}.should raise_error StandardError
For now I'm just using StandardError to make sure it's working.
1)
StandardError in 'Participant should never allow more participants than players'
This game is alrea...
Today I ran into an issue using RoR to stub calls to AR objects. I thought that I'd be able to do something along the lines of :
stub.instance_of(BankAccount).save_to_other_spot { true }
However when I tried this method it didn't seem to stub the method at all and it would end up running the original method I was trying to stub. I con...
One of my specs fails when I run it via "rake spec" but passes when I use the RSpec executable "spec".
The spec fails when I use a url helper in a ActionMailer view. The error message is:
auction_url failed to generate from {:action=>"show", :state=>"asd", :slug=>"asd", :controller=>"auctions"}, expected: {:action=>"show", :controller=...
So I'm extending a friend's project and he's done all the development with TDD using Test::Unit
I use Rspec in all my projects and want to avoid having to learn a new tool. Is it bad practice to have 2 separate test suites, one in Test::Unit and one in Rspec?
I've also considered using Shoulda to extend Test::Unit to sort of feel like ...
I stubbed the subset billed? method
subset.stub(:billed?).and_return(true)
line_item has a delegate for billed? to subset billed?
when I call the methods the following occurs
(rdb:1) subset.billed?
true
(rdb:1) subset.line_items[0].billed?
false
(rdb:1) subset === subset.line_items[0].order_subset
true
(rdb:1) subset.bill...
In ApplicationHelper I have such code:
def inside_layout layout = 'application', &block
@template.instance_variable_set '@content_for_layout', capture(&block)
concat \
@template.render :file => "layouts/#{layout}", :use_full_path => true
end
which behaves like this:
application.html.haml:
!!!
%html
%head
...
%body
...
I've got a controller called SolutionsController whose index action is different depending on the value of params[:user_id]. If its nil, then it simply displays all of the solutions on my site, but if its not nil, then it displays all of the solutions for the given user id.
Here it is:
def index
if(params[:user_id])
@solutio...
Let's say I have a big spec file with 20 tests because I'm testing a large model and I had no other way of doing it :
describe Blah
it "should do X" do ... end
it "should do Y" do ... end
...
it "should do Z" do ... end
end
Running a single file is faster than running the whole test suite, but it's still pretty long. Is there ...
I' trying to fix this for hours...
I have this on a controller rspec test:
it "show action should render show template" do
task = Task.make
task.mission = Mission.make
get :show, :id => task
response.should render_template(:show)
end
But it fails rendering the view because of this:
<%=h @task.mission.name %>
I ...
How can database views be tested in Rspec? Every scenario is wrapped in a transaction and the data does not look like it is being persisted to the database (MySQL in my case). My view returns with an empty result set because none of the records are being persisted in the transaction. I am validating that the records are not being stor...
I want to stub out a method only for a certain parameter. Say I have a class
class Foo
def bar(i)
i*2
end
end
Now I want to stub out the method bar only for calls with a value of say 3 and return the method return value in all other cases:
>> foo = Foo.new
>> foo.bar(2)
=> 4
>> foo.stub!(:bar).with(3).and_return(:borked)
>> f...