问题描述
我想获得,,,和一起玩。
I would like to get machinist, machinist_mongo, mongo_mapper, cucumber and pickle to play nice together.
目前我有机械师与我的所有蓝图配置和我使用黄瓜做BDD。到现在为止还挺好。我的问题是我必须为我的所有机械师蓝图写自定义黄瓜步骤。这不是一个真正的问题本身,因为它不是阻止我在我的轨道,但作为一个.NET开发人员检查rails,感觉非常脏,必须为每个蓝图写一个步骤,而在.NET我可能使用反射。
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.
有什么办法我可以得到pickle的内置 capture_model
, capture_plural_factory
等,以识别我的机械师蓝图?
Is there any way I can get pickle's built in capture_model
, capture_plural_factory
, etc, to recognize my machinist blueprints?
我很自信我的机械师配置和设置正确,因为当我使用 blueprintname.make
,在自定义黄瓜步骤中,一切正常。
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版本:
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
机械师1.0.6
machinist_mongo 1.1.1
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
require 'pickle/world'
Pickle.configure do |config|
config.adapters = [:machinist]
end
code> config.adapters = [:machinist,Machinist :: MongoMapperAdapter] 但我得到一个错误,说明没有方法工厂
Machinist :: MongoMapperAdapter
。
I tried using config.adapters = [:machinist, Machinist::MongoMapperAdapter]
but I get an error stating that there is no method factories
for Machinist::MongoMapperAdapter
.
features / support / machinist.rb:
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(为了清楚起见,截断)
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
app/models/access_code.rb
class AccessCode
include MongoMapper::Document
key :code, String, :required => true
end
推荐答案
头对墙,我有一切都工作(我说大多是工作,因为我不知道如果有什么问题,我还没有发现)。
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.
要解决这个问题,并获得我的步骤使用,我更改了 MongoMapper :: Document
包含 Pickle :: Adapter :: Base
。我使用了来自为例。我仍然需要,大概是把我的机械师蓝图挂钩。
To resolve the issue, and get my cucumber steps working with pickle, I changed MongoMapper::Document
to include Pickle::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.
我不能把 def self.model_classes
中的代码归功于它从。
I can't take credit for the code in def self.model_classes
- it is stolen from tjtuom's pickle fork.
PS。如果这是完全错误的做法,请随意批评或提出建议,我是一个完整的ruby noob。
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.
module MongoMapper::Document
module PickleAdapter
include Pickle::Adapter::Base
def self.model_classes
@@model_classes ||= ::MongoMapper::Document.descendants.to_a +
::MongoMapper::Document.descendants.map { |klass| klass.subclasses }.flatten
end
# get a list of column names for a given class
def self.column_names(klass)
klass.column_names
end
# Get an instance by id of the model
def self.get_model(klass, id)
klass.find(id)
end
# Find the first instance matching conditions
def self.find_first_model(klass, conditions)
klass.find(:first, :conditions => conditions)
end
# Find all models matching conditions
def self.find_all_models(klass, conditions)
klass.find(:all, :conditions => conditions)
end
end
end
为机械师设置酸洗:
Pickle.configure do |config|
config.adapters = [:machinist]
end
要配置 mongo:
To configure database_cleaner for mongo:
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.orm = 'mongo_mapper'
DatabaseCleaner.strategy = :truncation
这篇关于我如何获得黄瓜和腌菜使用mongo_mapper,machinist和machinist_mongo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!