Hi,
Is it possible to cover my controller, that is highly depeinding on Etags with unit tests?
Here's what i'm trying to do:
in case if page is not stale (meaning that it's fresh), i'm adding some header to response.
When i'm trying to test it all (rspec), no matter how many similar requests i have, i still receive 200 OK instead of ...
Normally to pass parameters via in RSpec we do:
params[:my_key] = my_value
get :my_method
Where my_method deals with what it received from params. But in my controller I have a method, which takes args directly i.e.:
def my_method(*args)
...
end
How do I call the method with those args from within the test? I've tried get :my_met...
Its a rails 2.3.5 app. I'm using the rspec and cucumber for testing.
When I run autospec, it runs correctly with the warning (Not running features. To run features in autotest, set AUTOFEATURE=true.) as below:
[~/rails_apps/automation (campaign)⚡] ➔ autospec
(Not running features. To run features in autotest, set AUTOFEATURE=true.)
(...
Hi there,
I've coded the following spec:
it "should call user.invite_friend" do
user = mock_model(User, :id => 1)
other_user = mock_model(User, :id => 2)
User.stub!(:find).with(user.id).and_return(user)
User.stub!(:find).with(other_user.id).and_return(other_user)
user.should_receive(:invite_friend).with(other_us...
In one of my project with some existing code, some code is covered by _test.rb file, other is by _spec.rb and we introduced .feature
It became a nice mixture of stuff to check.
I am stumped how to run .feature, _spec.rb and _test.rb for red-green cycles.
...
I am learning how to write test cases using Rspec. I have a simple Post Comments Scaffold where a Post can have many Comments. I am testing this using Rspec. How should i go about checking for Post :has_many :comments. Should I stub Post.comments method and then check this with by returning a mock object of array of comment objects? Is t...
How to test the following example?
class Post < ActiveRecord::Base
belongs_to :discussion
def after_save # or after_create
discussion.touch
end
end
EDIT: I have found a nicer way to write the code above.
class Post < ActiveRecord::Base
belongs_to :discussion, :touch => true
end
...
As far as I know, should_receive is applied only to mock objects. What I want is to check, if a certain Class (not object) received a certain message, like:
User.should_receive(:all).once
How do I do that?
UPD. Commonly, writing test for models and controllers we can write User.should_receive(:smth).once. But in my case I'm testing a...
/usr/local/bin/ruby -rrubygems -e "require 'redgreen'" /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec --autospec <files_here> -O spec/spec.opts
invalid option: --autospec
Test::Unit automatic runner.
Usage: -e [options] [-- untouched arguments]
which spec says "/usr/local/bin/spec"
which autospec says "/usr/local/bin/autospec"...
I've just installed a ZenTest to use autotest in my project. I use rspec and have an integration folder inside it. As I don't want all my integration tests run every single time I start autospec , so I'd like to somehow restrict autospec from running tests in that folder.
How do I exclude a chosen folder inside a /spec from running by a...
Within my controller specs I am stubbing out valid? for some routing tests, (based on Ryan Bates nifty_scaffold) as follows :-
it "create action should render new template when model is invalid" do
Company.any_instance.stubs(:valid?).returns(false)
post :create
response.should render_template(:new)
end
This is fine when I test t...
Following is the error i receive while running test cases written using rpsec. The strange thing is the test were running fine until early yesterday. Can someone guide me towards a solution. I am new to RSpec and and using Rspec and rspec-rails as plugins in my app. and i have no clue to what went wrong.
F:/Spritle/programs/ruby 1.86/li...
How do I test before_filter with rspec and remarkable. With only rspec I would do something like:
controller.stub(:logged_in?).and_return(true)
But with remarkable this results in:
undefined local variable or method `controller' for #<Class:0x7f8f056ef3c0> (NameError)
...
I have written my basic models and defined their associations as well as the migrations to create the associated tables.
EDIT - Adding emphasis to what I specifically want to test.
I want to be able to test:
The associations are configured as intended
The table structures support the associations properly
I've written FG factorie...
I've been trying to debug some super slow performance in running my cucumber features. I've run various calls through ruby-prof and think I see the bottlenecks (not too familiar with using ruby-prof) but do not know the cause or more important the solution. I've include below the output from running rake cucumber.
http://dl.dropbox.co...
Hi - I'm trying out rspec, and immediately hit a wall when it doesn't seem to load db records I know exist. Here's my fairly simple spec (no tests yet).
require File.expand_path(File.dirname(__FILE__) + '../spec_helper')
describe SomeModel do
before :each do
@user1 = User.find(1)
@user2 = User.find(2)
end
it "should do ...
Hi.
Is there something like Spork for Jruby too? We want to parallelize our specs to run faster and pre-load the classes while running the rake task; however we have not been able to do so.
Since our project is considerable in size, specs take about 15 minutes to complete and this poses a serious challenge to quick turnaround.
Any ide...
I have just installed Rspec and Rspec-rails. When i try to run the test, it says:
rake aborted!
Command /opt/local/bin/ruby -I"lib" "/opt/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec" "spec/controllers/free_controller_spec.rb" --options "/Volumes/Trash/dev/app/trunk/spec/spec.opts" failed
Full log here: http://pastie.org/939211
...
I'm having trouble with and RSpec view test. I'm using nested resources and the model with a belongs_to association.
Here's what I have so far:
describe "/images/edit.html.erb" do
include ImagesHelper
before(:each) do
@image_pool = stub_model(ImagePool, :new_record => false,
:base_path => '/')
...
I am trying to cleanup my specs as they are becoming extremely repetitive.
I have the following spec
describe "Countries API" do
it "should render a country list" do
co1 = Factory(:country)
co2 = Factory(:country)
result = invoke :GetCountryList, "empty_auth"
result.should be_an_instance_of(Api::GetCount...