mocha

How are both of these tests passing?

I'm using Shoulda, Mocha, and Test::Unit for testing. I have the following controller and test: class FoosController < ApplicationController caches_action :show def show @foo = requested_foo end private def requested_foo Foo.find(params[:id]) end end class FoosCachingTest < ActionController::IntegrationTest def s...

How to mock to twitter api using Ruby on Rails?

I'm developing a application that uses the twitter API. I'm currently using rspec with mocha, but I found it to be cumbersome and I cannot reuse the mocking that I create for a give method. Is there a way that you can have for a give call, return something, and for another call return something else? Or it needs to be by each method? ...

Why does rspec redirect not get full route during test?

I'm attempting the following functional test on the controller. I'm using the following RSpec2 Rails 3 Shoudla Mocha Here's the test context "POST on create should be successful" do before(:each) do Model.any_instance.expects(:save).returns(true).once Model.any_instance.stubs(:id).returns(1) post :create, :model => {}...

How do you test an AJAX request with RSpec/RoR?

I'm fairly new to RoR and recently started learning BDD/Rspec for testing my application. I've been looking for a way to spec an AJAX request, but so far I haven't found much documentation on this at all. Anyone know how to do this? I'm using rails 2.3.8, rspec 1.3.0 and mocha 0.9.8 for my stubs (which I'm also in the process of le...

How to mock an instance method of an already mocked object ?

I need to mock the following: Class User def facebook #returns an instance of a facebook gem end end So in my User tests, to access the User's facebook info I need to call user.facebook.me.info to retrieve its info. If I want to mock this, I'm currently using the following: @user = Factory(:user) facebook = mock() me = mock()...

RoR: Chained Stub using Mocha

Is it possible to stub an entire chain using Mocha? For example, I want to stub: User.first.posts.find(params[:id]) such that it returns a predefined post instance instead of accessing the database. Ideally, I'd want to do something like: @post = Post.new User.any_instance.stubs(:posts,:find).returns(@post) As you can see, I'm stub...

Mocking with rspec and mocha together

For a test suite that's already using mocha for mocking, can new tests be written with rspec mocking? maybe turn that on before(:all) and turn it back to mocha after(:all) I tried changing the Spec::Runner configuration at run-time and that didn't seem to work with mocking ...