I have a sinatra app that uses neo4j as a graph db. the app accesses the db through neography as a REST client.
I want to mock this client for testing purposes, using rspec. what s the best practice to achieve this?
I have a sinatra app that uses neo4j as a graph db. the app accesses the db through neography as a REST client.
I want to mock this client for testing purposes, using rspec. what s the best practice to achieve this?
您在此有几种选择:
1: 跟踪这一联系:http://net.tuts.com/tutorials/ruby/even-an-api-wrapper-in-ruby-with-td/
It explains step by step how to do it using webmock and the vcr gem. The idea is you run your tests against a live database the first time, vcr records them, and afterwards your tests will run off the recorded answers.
Two: You can run your tests against a fresh db in a CI virtual machine environment. Take a look at the travis.yml file for Neography:
文字:“bundle exec rake Emerg4j:install Emerg4j:start spectrace”
and the results: http://travis-ci.org/#!/maxdemarzi/neography
三个方面:你可以在比你的dev夫或假肢不同的港口数目上进行 test检,在座标上看上去。
It s a good question, so I ll do a post on it on my blog one of these days at http://maxdemarzi.com
我的创始回答:
sinatra app:
require sinatra
module Backend
class Neography
# stuff
end
end
helpers Backend
before do
@neo = Backend::Neography.new
end
get /:id do
"#{@neo.get_node(params[:id])}"
end
光谱:
describe The App do
include Rack::Test::Methods
def app
Sinatra::Application
end
def mock_neography
@neo_mock = mock("Backend::Neography")
@neo_mock.stub!("get_node") {"something else"}
Backend::Neography.stub(:new).with(any_args()).and_return(@neo_mock)
end
it "gets a node" do
mock_neography
get /5
last_response.should be_ok
end
end
我试图阅读即将提出的申请,并根据请求中价值分立的3.0作出模拟反应。 我为此使用了以下大写。
I am using VS2010 B2 and EF4 B2 and trying to use Rhino Mocks to mock the entity context generated by EEF. var context = MockRepository.GenerateMock<SomeDBEntities>(); IObjectSet<TxMode> ...
I have an interesting situation where I am refactoring a bunch of ObjC iPhone code to create a C++ API. I m a novice to C++ and looking into C++ mocking frameworks to augment the work I d done using ...
I m looking for some examples on how to do the following Mock Tests using StructureMap or Unity with NUnit. I have the following code structure public interface IDAL { List<Model> Method1(...
I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...
I have a method that I want to test which expects an IEnumerable<T> as a parameter. I m currently mocking the contents of the IEnumerable<T> as follows (Using Moq): var mockParent = new ...
I am currently developing an GUI to an embedded system. (I am using GUI to descripe my app opposed to interface to avoid confusion with the progamatic meaning) Context I have created a class which ...
see also "What should I consider when choosing a mocking framework for .Net" I m trying to decide on a mocking framework to use on a .NET project I ve recently embarked on. I d like to speed my ...