我有这个代码:
19 context 'overriding at fabricate time' do
20 let(:fabricated_object) do
21 Fabricate(
22 "#{fabricator_name}_with_children", do
23 string_field: 'new content',
24 number_field: 10,
25 nil_field: nil,
26 placeholder: 'is not invoked',
27 dynamic_field: { 'new dynamic content' }
28 end)
29 end
制造商:
1 class Fabrication::Fabricator
2
3 def self.build(name, overrides={}, &block)
4 fail_if_initializing(name)
5 schematic(name).build(overrides, &block)
6 end
7
8 def self.fabricate(name, overrides={}, &block)
9 fail_if_initializing(name)
10 schematic(name).fabricate(overrides, &block)
11 end
12
13 def self.to_attributes(name, overrides={}, &block)
14 fail_if_initializing(name)
15 schematic(name).to_attributes(overrides, &block)
16 end
17
18 def self.to_params(name, overrides={}, &block)
19 fail_if_initializing(name)
20 schematic(name).to_params(overrides, &block)
21 end
22
23 private
24
25 def self.fail_if_initializing(name)
26 raise Fabrication::MisplacedFabricateError.new(name) if Fabrication.manager.initializing?
27 end
28
29 def self.schematic(name)
30 Fabrication::Support.find_definitions if Fabrication.manager.empty?
31 Fabrication.manager[name] || raise(Fabrication::UnknownFabricatorError.new(name))
32 end
33
34 end
但我不断得到
integration_spec.rb:23: syntax error, unexpected ':', expecting ')' (SyntaxError)
string_field: 'new content',
^
/home/durrantm/Dropbox/96_2013/work/code/ruby/fabrication_temp/spec/_seded/integration_spec.rb:23: syntax error, unexpected ',', expecting kEND
/home/durrantm/Dropbox/96_2013/work/code/ruby/fabrication_temp/spec/_seded/integration_spec.rb:25: Can't assign to nil
/home/durrantm/Dropbox/96_2013/work/code/ruby/fabrication_temp/spec/_seded/integration_spec.rb:26: syntax error, unexpected ':', expecting '='
placeholder: 'is not invoked'
^
/home/durrantm/Dropbox/96_2013/work/code/ruby/fabrication_temp/spec/_seded/integration_spec.rb:27: syntax error, unexpected ')', expecting kEND
...
我怎样才能解决这个问题?我已经尝试以多种方式格式化哈希,但都没有奏效。
曾经以这种格式工作的代码(我试图期待):
context 'overriding at fabricate time' do
let(:fabricated_object) do
Fabricate(
"#{fabricator_name}_with_children",
string_field: 'new content',
number_field: 10,
nil_field: nil,
placeholder: 'is not invoked'
) do
dynamic_field { 'new dynamic content' }
end
end
我也试过:
19 context 'overriding at fabricate time' do
20 let(:fabricated_object) do
21 Fabricate(
22 "#{fabricator_name}_with_children",
23 { string_field: "new content",
24 number_field: 10,
25 nil_field: nil,
26 placeholder: 'is not invoked',
27 dynamic_field: { 'new dynamic content' }})
28
29 end
但得到了
integration_spec.rb:23: odd number list for Hash (SyntaxError)
{ string_field: "new content",