stub

RSpec: Stub chains with arguments?

自作多情 提交于 2019-12-18 01:28:34
问题 Just wondering if/how arguments can be passed in rspec stub chains. To give an example, suppose I have the following action: def index @payments = Payment.order(:updated_at).where(:paid => true) @bad_payments = Payment.order(:some_other_field).where(:paid => false) end In my controller spec, I'd like to be able to stub out both methods and return different results. If only the @payments field were in the action I'd use something like Payment.stub_chain(:order, :where) { return_this } But of

EntityFunctions.TruncateTime and unit tests

会有一股神秘感。 提交于 2019-12-17 22:57:18
问题 I'm using System.Data.Objects.EntityFunctions.TruncateTime method to get date part of a datetime in my query: if (searchOptions.Date.HasValue) query = query.Where(c => EntityFunctions.TruncateTime(c.Date) == searchOptions.Date); This method (I believe the same applies to other EntityFunctions methods) cannot be executed outside of LINQ to Entities. Executing this code in a unit test, which effectively is LINQ to objects, causes a NotSupportedException to be thrown: System

What does “to stub” mean in programming?

醉酒当歌 提交于 2019-12-17 21:27:17
问题 For example, what does it mean in this quote? Integrating with an external API is almost a guarantee in any modern web app. To effectively test such integration, you need to stub it out. A good stub should be easy to create and consistently up-to-date with actual, current API responses. In this post, we’ll outline a testing strategy using stubs for an external API. 回答1: A stub is a controllable replacement for an Existing Dependency (or collaborator) in the system. By using a stub, you can

Prevent stubbing of equals method

怎甘沉沦 提交于 2019-12-17 20:19:10
问题 I would like to test my class' equals() method but Mockito seems to be calling the stub version every time. My test is as follows; PluginResourceAdapter adapter = mock (PluginResourceAdapter.class); PluginResourceAdapter other = mock (PluginResourceAdapter.class); when(adapter.getNumberOfEndpointActivation()).thenReturn(1); when(other.getNumberOfEndpointActivation()).thenReturn(0); boolean result = adapter.equals(other); assertFalse(result); I know I cannot stub the equals method which means

How do I stub things in MiniTest?

青春壹個敷衍的年華 提交于 2019-12-17 17:31:47
问题 Within my test I want to stub a canned response for any instance of a class. It might look like something like: Book.stubs(:title).any_instance().returns("War and Peace") Then whenever I call @book.title it returns "War and Peace". Is there a way to do this within MiniTest? If yes, can you give me an example code snippet? Or do I need something like mocha? MiniTest does support Mocks but Mocks are overkill for what I need. 回答1: # Create a mock object book = MiniTest::Mock.new # Set the mock

What is a “Stub”?

戏子无情 提交于 2019-12-17 15:19:20
问题 So, carrying on with my new years resolution to get more in to TDD, I am now starting to work more with Rhino Mocks. One thing I am keen to do is to make sure I really grok what I am getting in to, so I wanted to check my understanding of what I have seen so far (and I thought it would be good to get it up here as a resource). What is a "Stub"? 回答1: Martin Fowler wrote an excellent article on this subject. From that article: Meszaros uses the term Test Double as the generic term for any kind

java.net.ConnectException :connection timed out: connect?

ぃ、小莉子 提交于 2019-12-17 06:11:34
问题 I have used RMI in my code : import java.rmi.*; public interface AddServerIntf extends Remote { double add(double d1,double d2) throws RemoteException; } import java.rmi.*; import java.rmi.server.*; public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf { public AddServerImpl() throws RemoteException { } public double add(double d1,double d2) throws RemoteException { return d1+d2; } } import java.net.*; import java.rmi.*; public class AddServer { public static void

groovy per instance metaClass method override doesnt work as expected in spock test

一笑奈何 提交于 2019-12-14 01:56:44
问题 having a problem I have a class with method called execute(). In some spock unit test i dummy out the execute method and give it a mock closure like this def setup () { rule = new DynamicRule () } def "test default execution " (){ given : "basic AORule " def mockres rule.metaClass.execute = {-> mockres = "did nothing"} //mock the action def res = rule.execute() expect : "execute should do nothing " mockres == "did nothing" } if i run this test it fails. in the idea editor it shows the mock

using rmic in netbeans

余生颓废 提交于 2019-12-14 01:40:24
问题 I have written rmi server code in netbeans 6.5. How can I use rmic in netbeans 6.5 so that I can create server_stub class? 回答1: If you use Spring's remote proxying ( RmiProxyfactoryBean ), you don't need to generate any stub/skel classes at all. Spring just does all the magic for you behind the scenes. You don't even need to implement the Remote interface! See the docs here 回答2: Why not edit the standard build.xml located in the project root directory? Include the Rmic Ant task. This will

PHPSpec and Laravel - how to handle double method not found issues

岁酱吖の 提交于 2019-12-13 05:59:06
问题 I appear to be having issues with my spec tests when it comes to stubs that are calling other methods. I've been following Laracasts 'hexagonal' approach for my controller to ensure it is only responsible for the HTTP layer. Controller <?php use Apes\Utilities\Connect; use \OAuth; class FacebookConnectController extends \BaseController { /** * @var $connect */ protected $connect; /** * Instantiates $connect * * @param $connect */ function __construct() { $this->connect = new Connect($this,