stub

Stubbing a before_filter with RSpec

Guys, I'm having trouble understanding why I can't seem to stub this controller method :load_user, since all of my tests fail if I change the actual implementation of :load_user to not return and instance of @user. Can anybody see why my stub (controller.stub!(:load_user).and_return(@user)) seems to fail to actually get called when ...

Which is the best isolation framework for Java? JMock, Easymock, Mockito, or other?

I realize this has been asked before, but the last time was in mid 2008. If you were starting a new project right now, which one would you use and why? What are their strengths/weaknesses regarding readability, usability, maintainability, and overall robustness? ...

Zend Framework/PHPUnit: How to Stub/Mock an object method that connects to a database?

In my Zend Framework project, I have a form that I am testing. In my form, a multi-select element gets its options from a model, which gets the data from the database. public function init() { $this->addElement('select', 'Region_ID', array('multiOptions' => $this->getRegions())); } protected function getRegions() { $mapper = ne...

Generate webservice stub from wsdl in Java

I am working on eclipse plugin which will have a wizard. This wizard will be available form example from context menu while mouse right click on Java editor. The wizard will be responsible for collecting such information as: location of WSDL filePackage name When the wizard finishes, I would like to have stub of a webservice described...

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

Software engineering with Ada: stubs; separate and compilation units

Hi, I'm with a mechanical engineering background but I'm interested to learn good software engineering practice with Ada. I have a few queries. Q1. If I understand correctly then someone can just write a package specification (ads) file, compile it and then compile the main program which is using the package. Later on, when one knows wh...

Mocha expectation on association build call failing

I have this example: # GET New context "on get to new" do it "should assign cardset" do @profile.cardsets.expects(:build).once.returns(Factory.stub(:cardset)) get :new assigns[:cardset].should_not be_nil end end To test this method: # GET /cardsets/new def new @cardset = current_user.cardsets.build end I am trying...

Why is stubbing not working correctly in Ruby Double (rr)?

I have a simple spec test in my Ruby on Rails application: stub.instance_of(Search).x { 3 } puts Search.new.x # displays 3 puts Search.first.x # gives me an error: undefined method `x' for #<Search:0xb5fabaa8> why does the third line fail? Search.first does return an instance of Search. Thanks ...

Where do you keep your Stubs?

One of the JUnit best practices is : same package, separate directories. I am wondering what is the equivalent for Mock classes ? Do you keep them in the same package as classes they are supposed to mock, but in the test directory ? or elsewhere ? ...

How to generate helper classes and stub code with wsdl2php for a PHP web service?

Hi, I have a WSDL generated by WCF and now this WSDL should be used to create a PHP web service. My WSDL contains mappings to custom .NET classes (complexType) and I would need a PHP WSDL tool which can generate the equivalent PHP classes as well as the stub code (server-side generation). I read that the wsdl2php would be the right too...

How do I stub out the flickraw library in my app's unit tests?

My Rails 2 app displays a slideshow of photos from Flickr via the flickraw library. My code works, but I'm stuck on how to properly write RSpec unit tests. I have a Slide class that encapsulates everything that my app needs from flickraw. It acts somewhat like a model object but doesn't use ActiveRecord. It doesn't do much work; it de...

What are stub files?

Can anyone explain stub files and show me a simple example? For example, key-ing name and age in our main exe, invokes a new exe created with the name and age in the label. ...

Installer Stub for large file

We've got a large program to install (1Gb) packaged into an installer already. Is there any easy way to use a download manager to ensure that our clients can download without any issues. I was thinking a simple stub that just downloads the file then executes once done. ...

Should Mock<SomeClassType>.SetupAllProperties() cause properties to return the values they are assigned?

When I use SetupAllProperties on a Mock, it works as expected: /// <summary> /// demos SetupAllProprties on an interface. This seems to work fine. /// </summary> [Test] public void Demo_SetupAllProperties_forAnInterface() { var mock = new Mock<IAddress>(); mock.SetupAllProperties(); var stub = mock.Object; stub.City = ...

How can I create and use a partial stub (in MoQ) without being tied to the concrete implimentation?

I have code that uses MoQ to create a partial stub. I'd prefer to interact with the interface instead of the concrete implementation so that I won't have to modify the unit test if I have a different implementation of the interface. So for example, I have a factory method such as: private Mock<ISomeInterface> ISomeInterfaceStubFactory...

How to stub Python methods without Mock

I'm a C# dev moving into some Python stuff, so I don't know what I'm doing just yet. I've read that you don't really need Dependency Injection with Python. I've been told you can instantiate objects in your code and have them run the way you want, however, you can point methods on those objects to my own stubs defined in my tests - supp...

How will this Ocaml type definition look in its C stub?

I've taken the following code from http://www.ocaml-tutorial.org/data_types_and_matching I've been trying to write a C stub for following, to invoke from our PHP codebase. I can't quite understand how (and if) I'm supposed to create a typedef for the following Ocaml type expr, and how I can access the function multiply_out from the C st...

Implementing a protected parameterless constructor for unit testing

If I have a type with a big-old (lots of params) constructor, is it a valid approach to implement a protected parameterless constructor simply for the purposes of creating a derived "Fake" type to use for stubbing in unit tests? The alternative is to extract an interface, but this is not always desireable in a codebase you do not have f...

what is a stub routine?

In regards to C what is a stub routine? Also an example would be much appreciated as well. ...

Stubbing Chained Queries in Rails 3 and Rspec

I'm trying to test a scope I have that is based upon a chain of other scopes. ("public_stream" below). scope :public, where("entries.privacy = 'public'") scope :completed, where("entries.observation <> '' AND entries.application <> ''") scope :without_user, lambda { |user| where("entries.user_id <> ?", user.id) } scope :public_stream, l...