1
votes

I'm using FactoryBot to help test my Rails application.

It works great, except I get an error when trying to define a text field.

For a string, you simply use name { "John" }, but I have one row, method, in my db which is a text field. When I try to define that row as follows:

method { "Some method here" }

it returns

ArgumentError:
  wrong number of arguments (given 0, expected 1)

Anyone know the syntax to define a text field with FactoryBot?

1
One "row method", how's that? - de-russification
I don't really think there's enough information to answer this question. If it's a text field attribute on the model you're creating a factory for, then name { 'John } inside the factory should work. If you have uniqueness validation on the column, it should fail with a different error. If you're declaring a let var in rspec, then you'd do something like let(:user) { create :user, name: 'John' }. Could you add more detail about the model and factory? - Allison

1 Answers

2
votes

method is defined on Object by Ruby. If your table column is called "method", you're going to run into all sorts of issues. You may be able to work around this specific error, but more will likely crop up. My best advice would be to rename your column and move on.

Edit: To clarify - this has nothing to do with your column type. It has to do with your column being named "method."