mocha

Practicing BDD with python

Which are the most advanced frameworks and tools there are available for python for practicing Behavior Driven Development? Especially finding similar tools as rspec and mocha for ruby would be great. ...

Returning mock objects from factory girl

I am using Mocha and Factory_girl in a JRuby rails application. When I call the factory I would like to return the objects with some mocking already done. Here is a code snippet of what I am trying to do. Factory.define :tweet_feed_with_tweets, :parent => :tweet_feed do |t| t.expects(:pull_tweets).returns([Factory.build(:status),Fac...

Mocha : How do you set up an expectation for an instance method?

Assume this ruby code: class User def self.failed_login!(email) user = User.find_by_email(email) if user user.failed_login_count = user.failed_login_count + 1 user.save end end end I want to write a test that tests that user.save is never called when an invalid email is given. E.g.: it "should not incremen...

MochaUI: 'A is null' when adding columns

I've just downloaded MochaUI, and I'm playing around trying to build an interface. I've successfully created windows, but I'm having trouble when it comes to layouts with columns. I've included all of the libraries in the same order as the demo, and this is in my init code: window.addEvent('domready', function(){ new MochaUI.Colum...

Changing mocha default expects exactly once

I just started using mocha and I find it annoying that when creating a new mock object, mocha expects it to be called exactly once. I have helper methods to generate my mocks and I'm doing something like this my_mock = mock(HashOfParameters) All of the parameters might not get called for each test method so it will raise an error: ...

Installing Mocha 0.9.7 in a Rails 2.3.3 project

I installed the Mocha 0.9.7 Rails plug-in using: $ script/plugin install git://github.com/floehopper/mocha.git (Just followed instruction in http://mocha.rubyforge.org/) Then, I have the following set-up defined in my functional test def setup @controller.expects(:logged_in?).returns(true) @controller.expects(:admin_user?).retur...

Mocking website url thumbnailing feature in Rails?

Hi, I just started testing a new rails project, and I want a feature to webthumb the url into image. And now I want to test this feature. I'm trying to use the ThoughtBot family - shoulda factory-girl paperclip. For mocking, mocha. How can I test this feature? ...

Cannot load gem in IronRuby

I already removed all environment variables and ruby/ironruby directories and reinstalled it from scratch. And then I installed mocha through igem. Here are my outputs. $ ir IronRuby 0.9.1.0 on .NET 2.0.50727.3082 Copyright (c) Microsoft Corporation. All rights reserved. >>> require 'mocha' :0:in `require': no such file to load -- moch...

Mocha + Cucumber to mock the Net response

The following is the app/models/websites.rb class Masterpiece < ActiveRecord::Base validates_presence_of :title, :link validates_uri_existence_of :link, :allow_redirect => false end The second validation is from the plugin Validates Existence of URI plugin The following is the features/support/mocha.rb file require 'mocha' W...

Rails Test & Mocha: How to stub specific model - conditional any_instance ?

I want to stub just a specific model, but not only a specific object and not every instance E.g. Given class 'Person' with attributes 'name' (string) and 'cool' (boolean). We have two models: person_bill: name: bill cool: false person_steve: name: steve cool: false Now I want to stub just steve, which works alright: p1...

Variable Passing in Rails Controller Tests

I am doing some controller testing with RSpec and Mocha. Here is an example describe MenuItemsController, "creating a new menu item" do integrate_views fixtures :menu_items it "should redirect to index with a notice on successful save" do MenuItem.any_instance.stubs(:valid?).returns(true) post 'create' assigns[:menu_i...

Stubbing Sinatra helper in Cucumber

I am currently struggling with stubbing out a helper method of my Sinatra app from within Cucumber. I have a Sinatra app with simple session authentication (by cookies) and I want to turn of authentication by stubbing out the logged_in? helper method for my Cucumber scenarios. There seems to be a problem with Sinatra and Cucumber conce...

Does mocha run the code in a stub (Rails)?

Im new to tdd and stubbing. When I stub a method im assumng that any code within that method does not get executed? Im trying to fake the method raising an exception but the results of my test indicate that the code in that method is being executed rather than bypassed. can anyone help explain why? My stubbing is @logged_in_user.subs...

Difference between RR mock.instance_of and Mocha any_instance

I have the following rspec code: require 'spec_helper' require 'mocha' require 'rr' describe ProjectsController, "creating a new project" do integrate_views it "should redirect to project with a notice on successful save" do Project.any_instance.stubs(:valid?).returns(true) #mock.instance_of(Project).valid? {true} Proj...

Does a mocked method's code actually run

Hi I'm using Mocha for a Rails project. I'm new to TDD so please forgive me if this is a stupid question. If I have this @client.expects(:create_config).once.returns(true) then am I right in assuming that the code in create_config() won't be run and instead true will just be returned? ...

mocha and nested objects

Excuse if this is a silly question, I am new to mocking. I am able to use mocha to do things like: person.expects(:first_name).returns('David') How can I mock a nested object? Say I have a Product that belongs to a Person and I want to get the first name of that person. In my app I might do it like this: product.person.first_name ...

Mocking Sort With Mocha

How can I mock an array's sort expect a lambda expression? This is a trivial example of my problem: # initializing the data l = lambda { |a,b| a <=> b } array = [ 1, 2, 3, 4, 5 ] sorted_array = [ 2, 3, 8, 9, 1] # I expect that sort will be called using the lambda as a parameter array.expects(:sort).with( l ).returns( sorted_array ) #...

Mocha no longer can be loaded after installing will_paginate 3.0pre

So I came about the strangest rails bug. I have been starting a new rails3 app, and just installed will_paginate 3.0pre. Unfortunately the rails 3.0.0.beta2 update made some of will_paginate 3.0pre code deprecated. I did a quick fix. In gems/will_paginate-3.0.pre/lib/will_paginate/railtie.rb: ... #railtie_name :will_paginate #Old co...

Is there a way to undo Mocha stubbing of any_instance?

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...

How to return a dynamic value from a Mocha mock in Ruby

The gist of my problem is as follows:- I'm writing a Mocha mock in Ruby for the method represented as "post_to_embassy" below. It is not really our concern, for the purpose of describing the problem, what the actual method does. But I need the mock to return a dynamic value. The proc '&prc' below is executing rightly in place of the act...