rspec

Errors with RSpec, Shouda, and Rails 3: undefined method `response_code'

I'm not sure why I am getting these errors, seemingly only on the Shoulda matcher tests. Any advice would be helpful. http://pastie.org/1020788 ...

Shoulda rspec matchers :on => :create

I am using some of the Shoulda rspec matchers to the test my model, one of them being: describe Issue do it { should_not allow_value("test").for(:priority) } end My problem with this is that my validation in my model looks like this: validates_format_of :priority, :with => /^(Low|Normal|High|Urgent)$/, :on => :update So when runn...

Test page helpers in rails app

I have some page helpers in application, something such as: # ajax_helper.rb module AjaxHelper def update_counter(new_value) page.replace_html :counter, :partial => 'counter', :locals => { :value => new_value} end end # update.fbjs.rjs .... page.update_counter(new_value) ..... What is the best way to test this helper method? ...

RSpec Test Case Doubt

Hi, Following is a test case in RailsTutorial. Generally I understand the syntax, But in this case, they define the @invalid_attr variable, but they dont seem to be using it. Infact in this line @user.should_receive(:update_attributes).and_return(false), I think @user would have all the values from the factory, rather than @inva...

Testing models with relationships and callbacks in Rails with RSpec and Factory_Girl

I'm still a working on learning RSpec so I'm sorry if completely overlooked something... I'm writing a test for a recipe that has many ingredients. The ingredients are actually added as a percent (with a total % column on the formulation) so I want to make sure that the total column updates after every save. So right now my RSpec test...

Rails 3 Autotest is saying "command not found", any ideas?

Hi... I've been trying to setup autotest with rails 3 beta4 but I getting a "-bash: autotest: command not found" -- any ideas? I installed it by putting the gem in my gemfile and then doing a bundle install.. ...

Do Ruby classes get cleared out between Rake tasks

I have a Rakefile that defines the spec task as task :spec => [:check_dependencies, :load_backends] And then runs the actual rspec tests. During the load_backends task, it loads a class called Story, but in the first spec test, defined?(Story) returns false. I'm assuming that it is intended behavior of Rake to start with a fresh env...

RSpec on Controller and Stubbing

I am pretty new to using rspec and am trying to write my tests for my controllers. I have this controller (I am using mocha for stubbing): class CardsController < ApplicationController before_filter :require_user def show @cardset = current_user.cardsets.find_by_id(params[:cardset_id]) if @cardset.nil? flash[:notice]...

setting rspec expectations on internal java method calls from jruby

I would love to be able to test java code with rspec under jruby, but can't see how to set expectations on internal java method calls. Given the following java: public class A { public String hi() { return hello(); } public String hello() { return "yo"; } } I would love to be able to do: describe 'A' do it 'should ...

Rspec2: undefined method 'post'

I'm having trouble runnng rspec2 and rails. Here's my log: 1) TrackController home path should be /track Failure/Error: Unable to find C to read failed line undefined method `route_for' for #<#<Class:01x5ffe7c2f>:0x77d36efb> # ./spec/controllers/track_controller_spec.rb:5 # :1 Here's my spec: describe UsersController,...

Authlogic and RSpec, errors only running all examples

I have a Profiles Controller that acts_as_authentic with AuthLogic and I am trying to test this action: class ProfilesController < ApplicationController before_filter :require_user, :except => ['new', 'create'] def index redirect_to(current_user) end end The following example is in a spec file with 18 other pending examples...

no such file to load -- rspec/autorun (LoadError)

attempting to use rspec2, rails3, and autotest. When running autotest I get stuck with the following: loading autotest/rails_rspec2 style: RailsRspec2 -------------------------------------------------------------------------------- ... ...bin/rspec:2:in `require': no such file to load -- rspec/autorun (LoadError) Looks like a path ...

How do I troubleshoot autotest infinite loop problems?

I'm using cucumber, rails3, rspec2 and autotest. I'm trying to figure out why my features are infinitely looping. I suspect it some file being changed during the tests but I'm not sure which one. I've added some exceptions to my .autotest with no dice. Are there any steps I can take to troubleshoot this problem? It'd be cool if I could...

Force controller to use current_user with mocking

I am trying to specify in my RSpec tests that my controller should use current_user.projects.find() instead of Project.find() I am using the Mocha mocking framework and was trying something like this: controller.current_user.projects.expects(:find).returns(@project) I have already mocked out controller.stubs(:current_user).returns(@pr...

Delayed Job not processed in rspec

I am trying to run rspecs for a custom delayed job (GetPage::GetPageJob), but I have a problem. When I run them, the jobs are well enqueued (that is to say, well inserted in the delayed_jobs table), but they are not processed by the job worker. Indeed, after launching "rake jobs:work RAILS_ENV=test" in a first terminal, and after runnin...

How to make 'Shoulda' test output easier to read and in Colour!

I currently working on a project which uses Spree Cart and which has hence forced me to switch from testing with RSpec to testing with Shoulda. I really like the output I get from rspec and am wanting to get similarly readable output using Shoulda. Specifically how do I achieve similar output as I would achieve with the rspec command ...

How to get fixtures data in describe scope

Hi. I'm struggling with spec for generic shared-exapmle here. But I can't get fixtures data in describe scope. Like below describe BlogController do fixtures :blogs { :show=>{:month=>blogs(:one).month, :day=>blogs(:one).day}, :edit=>{:month=>blogs(:one).month, :day=>blogs(:one).day} }.each |act, prams| do describe "blo...

Testing before_filter gets called in action

How would one test that when an action in controller is being accessed, that controller's before_filter will be executed? The before_filter is tested in separate example group so that there's no need to duplicate the tests for all actions that depend on the before_filter. If I have controller.should_receive(:my_before_filter) in my ...

Expectation for find not working, but expectation for find_by_id is

I have this controller code: # GET /cardsets/1 def show @cardset = current_user.cardsets.find_by_id(params[:id]) end And this RSpec test code (mocking with Mocha): # GET Show context "on get to show" do it "should assign cardset" do @cardset = Factory(:cardset) @profile = @cardset.profile @profile.cardsets.expects(:f...

Rspec: run just a few testcases from file

I have a bunch of tests in my spec file and in this way I run just one of them: rake spec SPEC=spec/integration/gardens_spec.rb SPEC_OPTS="-e \"should foo\"" If there is any way to run 2-3 of them with a single command(let's call those testcases "should bar" & "should baz")? ...