我正在开发一个文本游戏引擎,并且在开发探索模块时遇到了障碍。当我尝试Location
使用来自夹具的块参数实例化我的类时,我收到此错误:
ArgumentError,“参数数量错误(3 对 2)
对于此代码:
# in lib/explore/models/location.rb, line 15
class Location < RoundTable::Controllers::ActionDelegate
# ... code omitted for brevity
def initialize(slug, params = nil, &block)
# ... code omitted for brevity
if block_given?
parser = Explore::Parsers::LocationParser.new(self)
parser.instance_eval &block
end # if
end # constructor
# ... code omitted for brevity
end # class Location
# in spec/fixtures/models/locations.rb, line 38
location :mushroom_kingdom, :name => "Mushroom Kingdom" do
edges = Explore::Fixtures[:edges]
edges.each do |key, value|
go value.location, *value.params
end # each
end # location
# in spec/models/location_spec.rb, line 193
context "initialized with block" do
let :fixture do fixtures[:mushroom_kingdom] end
subject { described_class.new fixture.slug, fixture.params, &fixture.block }
it { puts subject.inspect }
end # context initialized with block
这很明显是某个地方的语法错误,其中一个块没有被转换为一个过程,反之亦然,但我已经检查了十几次代码并且找不到它。如果有眼尖的读者可以帮助我,我将永远感激不尽。
源文件:
完整的源代码在 Github 上可用,但分为两个存储库:
要运行代码或规范,插件代码需要放在 vendor/modules/plugins/explore 的引擎目录中。
回溯:
1) RoundTable::Vendor::Plugins::Explore::Models::Location initialization with block
Failure/Error: it { expect { described_class.new fixture.slug, fixture.params, &fixture.block }.not_to raise_error ArgumentError }
expected no ArgumentError, got #<ArgumentError: wrong number of arguments (3 for 2)>
# ./spec/models/location_spec.rb:33:in `block (4 levels) in <top (required)>'
2) RoundTable::Vendor::Plugins::Explore::Models::Location initialized with block
Failure/Error: subject { described_class.new fixture.slug, fixture.params, &fixture.block }
ArgumentError:
wrong number of arguments (3 for 2)
# ./lib/explore/parsers/location_parser.rb:39:in `go'
# ./spec/fixtures/models/locations.rb:41:in `block (2 levels) in <module:Models>'
# ./spec/fixtures/models/locations.rb:40:in `each'
# ./spec/fixtures/models/locations.rb:40:in `block in <module:Models>'
# ./lib/explore/models/location.rb:49:in `instance_eval'
# ./lib/explore/models/location.rb:49:in `initialize'
# ./spec/models/location_spec.rb:196:in `new'
# ./spec/models/location_spec.rb:196:in `block (3 levels) in <top (required)>'
# ./spec/models/location_spec.rb:198:in `block (3 levels) in <top (required)>'
编辑 2012 年 06 月 06 日:
- 用实际的、不合格的代码替换了示例代码
- 添加了完整项目的链接