如何让黄瓜和泡菜与 mongo_mapper、machinist 和 machinist_mongo 一起工作?
我想要机械师,machinist_mongo, mongo_mapper、黄瓜 和 pickle 一起玩得很好。
目前,我的机械师配置了所有蓝图,并且正在使用 Cucumber 来执行 BDD。到目前为止,一切都很好。我的问题是我必须为我的所有机械师蓝图编写自定义黄瓜步骤。这本身并不是一个真正的问题,因为它并没有阻止我继续前进,但作为一名检查 Rails 的 .NET 开发人员,必须为每个蓝图编写一个步骤感觉真的很脏,而在 .NET 中我可能可以使用反射。
有什么方法可以让pickle内置在capture_model
、capture_plural_factory
等中来识别我的机械师蓝图吗?
我非常有信心我已经正确配置和设置了机械师,因为当我在自定义黄瓜步骤中使用 blueprintname.make
时,一切正常。
宝石版本:
导轨2.3.8
黄瓜0.8.3
黄瓜导轨 0.3.2
蒙戈1.0.5
mongo_mapper 0.8.2
泡菜0.3.0
机械师1.0.6
machinist_mongo 1.1.1
features/support/pickle.rb:
require 'pickle/world'
Pickle.configure do |config|
config.adapters = [:machinist]
end
我尝试使用 config.adapters = [:machinist, Machinist::MongoMapperAdapter] 但收到一条错误,指出 没有方法
。factories
机械师::MongoMapperAdapter
features/support/machinist.rb:Machinist::MongoMapperAdapter:Class 的未定义方法“工厂”(NoMethodError) /usr/local/lib/ruby/gems/1.8/gems/pickle-0.3.0/lib/pickle/config.rb:25:in “工厂”
require 'machinist'
require 'machinist/mongo_mapper'
require "#{Rails.root}/spec/blueprints"
require 'database_cleaner'
Before { Sham.reset } # reset Shams in between scenarios
spec/blueprints.rb (truncated for clarity)require 'sham'
require 'faker'
Sham.code { Faker::Lorem.words 1 }
AccessCode.blueprint do
code
end
app/models/access_code.rbclass AccessCode
include MongoMapper::Document
key :code, String, :required => true
end
I would like to get machinist, machinist_mongo, mongo_mapper, cucumber and pickle to play nice together.
Currently I have machinist with all my blueprints configured and am using cucumber to do BDD. So far so good. My problem is I am having to write custom cucumber steps for all of my machinist blueprints. It is not really a problem per se, since it is not stopping me in my tracks, but as a .NET dev checking out rails, it feels really dirty to have to write a step for each blueprint whereas in .NET I could probably use reflection.
Is there any way I can get pickle's built in capture_model
, capture_plural_factory
, etc, to recognize my machinist blueprints?
I am pretty confident I have machinist configured and set up correctly, because when I use blueprintname.make
, in a custom cucumber step, everything works out correctly.
Gem versions:
rails 2.3.8
cucumber 0.8.3
cucumber-rails 0.3.2
mongo 1.0.5
mongo_mapper 0.8.2
pickle 0.3.0
machinist 1.0.6
machinist_mongo 1.1.1
features/support/pickle.rb:
require 'pickle/world'
Pickle.configure do |config|
config.adapters = [:machinist]
end
I tried using config.adapters = [:machinist, Machinist::MongoMapperAdapter]
but I get an error stating that there is no method factories
for Machinist::MongoMapperAdapter
.
undefined method `factories' for Machinist::MongoMapperAdapter:Class (NoMethodError) /usr/local/lib/ruby/gems/1.8/gems/pickle-0.3.0/lib/pickle/config.rb:25:in `factories'
features/support/machinist.rb:
require 'machinist'
require 'machinist/mongo_mapper'
require "#{Rails.root}/spec/blueprints"
require 'database_cleaner'
Before { Sham.reset } # reset Shams in between scenarios
spec/blueprints.rb (truncated for clarity)
require 'sham'
require 'faker'
Sham.code { Faker::Lorem.words 1 }
AccessCode.blueprint do
code
end
app/models/access_code.rb
class AccessCode
include MongoMapper::Document
key :code, String, :required => true
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过几天的头撞墙之后,我的一切基本上都在工作(我说大部分工作是因为我不确定是否有什么问题我还没有发现)。一旦我弄清楚了,修复实际上非常简单。
要解决此问题,请让我的 cucumber 步骤与 pickle,我更改了
MongoMapper::Document
以包含Pickle::Adapter::Base
。我使用了 附带的 lib/pickle/adapters/active_record.rb 和 data_mapper.rb (与 active_record.rb 相同的路径)以泡菜为例。我仍然需要 machinist_mongo,大概是为了将 pickle 连接到我的机械师蓝图。我不能将
def self.model_classes
中的代码归功于它 - 它是从 tjtuom 的 pickle 叉。附言。如果这是完全错误的做法,请随时批评或提出建议,我是一个十足的 ruby 菜鸟。
为机械师设置pickle:
为mongo配置database_cleaner:
After days of beating my head against the wall, I have everything mostly working (I say mostly working because I'm not sure if there is something wrong that I haven't discovered yet). The fix was actually pretty simple once I figured it out.
To resolve the issue, and get my cucumber steps working with pickle, I changed
MongoMapper::Document
to includePickle::Adapter::Base
. I used lib/pickle/adapters/active_record.rb and data_mapper.rb (same path as active_record.rb) that come with pickle as an example. I did still need machinist_mongo, presumably to hook up pickle to my machinist blueprints.I can't take credit for the code in
def self.model_classes
- it is stolen from tjtuom's pickle fork.PS. If this is the completely wrong way to do it, please feel free to criticize or give suggestions, I am a complete ruby noob.
Set up pickle for machinist:
To configure database_cleaner for mongo: