Skip to content

Commit 08936b1

Browse files
committed
Fix flakey example in Project::CreateRemix spec
I've reproduced this example failure locally as follows: bundle exec rspec --seed 58786 spec/concepts/project/create_remix_spec.rb:125 The problem was with the `component` factory using `Faker::Lorem.word` to generate `Component#name` [1] and then the example relying on the order of components which is partly based on `Component#name` [2]. And thus depending on the value of the generated name, `remixed_project.components.first` in the example didn't always refer to the component that the author intended and the assertion would fail, e.g. with the seed value of 58786, the original component had the name "ad" which comes before the new component name of "added_component" alphabetically. While I have some reservations about the use of Faker in spec setup, the simplest way to fix this is to find the new component by name before asserting against its attribute values. [1]: https://github.com/RaspberryPiFoundation/editor-api/blob/f397e870f2a33cce1f53b9104c52314f5233572c/spec/factories/component.rb#L5 [2]: https://github.com/RaspberryPiFoundation/editor-api/blob/f397e870f2a33cce1f53b9104c52314f5233572c/app/models/project.rb#L14
1 parent 1e0700c commit 08936b1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

spec/concepts/project/create_remix_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@
124124

125125
it 'persists the new component' do
126126
remixed_project = create_remix[:project]
127-
expect(remixed_project.components.first.attributes.symbolize_keys).to include(new_component_params)
127+
new_component = remixed_project.components.find { |c| c.name == new_component_params[:name] }
128+
expect(new_component.attributes.symbolize_keys).to include(new_component_params)
128129
end
129130
end
130131

0 commit comments

Comments
 (0)