1

RSpec seems to not output the right size of an array, almost like it does not process everything until it is asked to output something. What might be causing this?

Here is a portion of the spec code:

puts project.documents[0].tables[0].digits[5].relationships.size
project.documents[0].tables[0].digits[5].relationships.to_yaml
puts project.documents[0].tables[0].digits[5].relationships.size

The above code outputs:

2
6

There are no threads in the program unless DocSplit is using some sort of threads that I am unaware of. I think that this is an indicator of a larger problem, but I am lost as to what it might be.

Edit: The same thing occurs if I instead (replace the code above with the following) go through and save each of the relationships:

puts project.documents[0].tables[0].digits[5].relationships.size
project.documents.each do |doc|
  doc.tables[0].digits.each do |dig|
    dig.relationships.each do |rel|
      rel.save!
    end
  end
end
puts project.documents[0].tables[0].digits[5].relationships.size

Except that the results are:

1
6

Edit 2: The Relationship class also belongs to two digits and digits have many relationships. Could that be influential? Here is the code from relationship.rb

belongs_to :digit, :class_name => 'Digit', :foreign_key => 'digit_id'
belongs_to :digit_b, :class_name => 'Digit', :foreign_key => 'digit_b_id'
Justin Giboney
  • 3,271
  • 2
  • 19
  • 18
  • Is this a feature/integration spec? – Anthony E Apr 12 '16 at 22:50
  • I am trying to integrate multiple functions together, but if integration spec refers to something specific no. It is not testing front end stuff, so it should not be a feature test (I think). I am still kind of new to Rails and RSpec. – Justin Giboney Apr 13 '16 at 00:06
  • 1
    why not try `puts` on the before and after yaml version `puts project.documents[0].tables[0].digits[5].relationships` to see what changes when you call `to_yaml` ? – Taryn East Apr 13 '16 at 00:36
  • Do you mean save the to_yaml a variable? The lines are right next to each other. There should not be any changes occurring in the three lines. – Justin Giboney Apr 13 '16 at 00:49
  • Yes I am aware there should not be any change... so lets find out what change is happening (even though it shouldn't be there) ;) Quite possibly a reload is happening? or the yaml is mutating the set some other way... be but we can't know what way until you actually look (count tells us *something* changed, but not *what* the change was... which we need to know to solve this). – Taryn East Apr 13 '16 at 05:38
  • Could this have something to do with the fact that relationships belong to two digits? – Justin Giboney Apr 13 '16 at 21:19
  • Can you reproduce without rspec? For example in development ? – Frederick Cheung Apr 13 '16 at 21:24
  • It could be anything... but until you actually look at it with puts, we can't know... :) Can you please show us the output of puts on the actual relationships (not just the count of the relationships) ? – Taryn East Apr 13 '16 at 23:20

0 Answers0