谁有在功能测试中模拟facebook请求的最佳实践的建议?就像向请求中添加所有合适的参数一样简单吗?有没有一种方法可以把它们去掉呢?
我使用的是facebooker,它提供了一个模拟服务:
# A mock service that reads the Facebook response from fixtures
# Adapted from http://gist.github.com/44344
#
# Facebooker::MockService.fixture_path = 'path/to/dir'
# Facebooker::Session.current = Facebooker::MockSession.create但当我编写一个基本的get测试时,它会尝试将浏览器重定向到添加应用程序的facebook页面,我认为这表明模仿不起作用。
test "loads respondent" do
Facebooker::Session.current = Facebooker::MockSession.create
get :index
puts @response.body # => <html><body>You are being <a href="http://www.facebook.com/install.php?api_key=65e9d2c74b295cc5bcea935b584557f6&v=1.0&next=http%3A%2F%2Ftest.host%2Ffacebook">redirected</a>.</body></html>
end发布于 2010-02-05 12:47:05
我在最新版本的facebooker (1.0.58)上实现了这一点:
# test_helper.rb
require 'facebooker/mock/session'
require 'facebooker/mock/service'
Facebooker::MockService.fixture_path = File.join(RAILS_ROOT, 'test', 'fixtures', 'facebook')显然,您必须在fixtures中创建facebook目录,或者将其放在任何位置。在其中,您必须为每个facebook方法添加一个文件夹,并为您想要测试的不同类型的响应添加一个xml文件。我不得不添加facebook.users.getInfo和facebook.users.hasAppPermission。最简单的方法是为这些操作添加一个名为default.xml的文件,其中包含facebook wiki中的示例代码。
# Controller test
test "facebook action" do
get :index, {:fb_sig_added => true}, :facebook_session => Facebooker::MockSession.create
assert_response :success
end据我所知,fb_sig_added参数是必需的,因为内部facebooker逻辑在检查参数之前直接检查参数。对我来说,这似乎有点不靠谱,但也许这是有原因的。
https://stackoverflow.com/questions/2193942
复制相似问题