为 facebooker 控制器编写功能测试?
有人对在功能测试中模拟 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
Anyone have any tips for best practices for mocking out facebook requests in functional tests? Is it just as simple as adding all of the proper params to the request? Is there a way to stub those out?
I'm using facebooker, which comes with a mock service:
# 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
But when I write a basic get test, it tries to redirect the browser to the facebook page for adding the app, which I assume indicates that the mocking isn't working.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在最新版本的 facebooker (1.0.58) 上得到了这个工作:
显然你必须在固定装置中创建 facebook 目录,或者把它放在任何地方。在里面,您必须为每个 facebook 方法添加一个文件夹,并为您想要测试的不同类型的响应添加一个 xml 文件。我必须添加 facebook.users.getInfo 和 facebook.users.hasAppPermission 。最简单的方法就是添加一个名为
default.xml
的文件,其中包含来自 facebook wiki 的示例代码以执行这些操作。据我所知,fb_sig_added 参数是必要的,因为内部 facebooker 逻辑在检查该参数的会话之前直接检查参数。这对我来说似乎有点古怪,但也许是有原因的。
I got this working with the latest version of facebooker (1.0.58):
Obviously you will have to create the facebook directory in fixtures, or put it wherever. Inside you have to add a folder for each facebook method, and an xml file for the different types of responses you want to test for. I had to add
facebook.users.getInfo
andfacebook.users.hasAppPermission
. The easiest is just to add a file nameddefault.xml
with the example code from the facebook wiki for those actions.The fb_sig_added param is necessary as far as I can tell, because the internal facebooker logic checks the params directly before checking the session on that one. Which seems a bit wanky to me but maybe there's a reason for that.