ich mit factory on Rails ein seltsames Problem/Fehler habe:factory Rails Argument Fehler
ArgumentError: wrong number of arguments (given 1, expected 0)
/Users/bintoy/ruby-apps/tradegecko-exercise/exercise-app/spec/factories/object_records.rb:3:in `object_id'
Hinweis: Dies ist kein Duplikat Frage hieraus: Why am I getting FactoryGirl wrong number of arguments error? - Auch habe ich versucht, schon viele mögliche Lösungen wie das Problem mit FactoryGirls und Spring manuell zu laden oder zu bemerken. Aber keiner von ihnen hat funktioniert.
Das Setup ist, dass die Datenbank auf MongoDB (Mongoid Mapper) und hier sind die beteiligten Dateien basiert:
app/models/object_record.rb
class ObjectRecord
include Mongoid::Document
validates_presence_of :object_id, :object_type, :timestamp, :object_changes
validates_uniqueness_of :timestamp, :scope => [:object_id, :object_type]
field :object_id, type: Integer
field :object_type, type: String
field :timestamp, type: DateTime
field :object_changes, type: Hash
end
spec/features/user_searches_spec.rb
require 'spec_helper'
require 'rails_helper'
feature 'User searches on table' do
before :each do
FactoryGirl.create(:object_record)
end
scenario 'with an object id', js: true do
input_a_search '1'
expect(page).to have_css(".sorting_1", :text => "1")
save_and_open_screenshot
end
def input_a_search(search_word)
visit object_records_index_path
find('input[type=search]').set(search_word)
end
end
spec/Fabriken/object_records.rb
FactoryGirl.define do
factory :obect_record do
object_id 1
object_type "ObjectA"
timestamp 1465748715
object_changes ({:property1 => "val1"})
end
end
spec/support/factory_girl.rb
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
spec/spec_helper.rb
RSpec.configure do |config|
config.after(:all) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:suite) do
FactoryGirl.reload
end
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
end
spec/rails_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
require 'factory_girl_rails'
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
RSpec.configure do |config|
config.include Capybara::DSL
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
end
EDIT: Aus nur einem zufälligen Versuch Um dies zu debuggen, habe ich versucht, das Argument für object_id in der Fabrik wegzulassen, um zu sehen, was passiert:
FactoryGirl.define do
factory :obect_record do
object_id
...
Aber stattdessen habe ich diese Failure/Fehlermeldung aus Rspec:
1) User searches on table with an object id
Failure/Error: FactoryGirl.create(:object_record)
ArgumentError:
Factory not registered: object_record
# ./spec/features/user_searches_spec.rb:8:in `block (2 levels) in <top (required)>'
Alter, du rockst! Vielen Dank! Ich nehme das nicht. Das Problem mit allen Eingaben wurde gelöst. – Raven