× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Capybara tests not persisting to controller

Gabe Odess
Oct 22, 2014
<p>The crux of the issue was the database would not persist from the capybara test to the controller.  The solution was to remove the "cleaning" block from the DatabaseCleaner configuration.</p><p>We changed:</p><pre><span style="color:rgb(9, 78, 153)">RSpec</span><strong>.</strong>configure <strong>do</strong> <strong>|</strong>config<strong>|</strong> config<strong>.</strong>before(<span style="color:rgb(139, 70, 127)">:suite</span>) <strong>do</strong> <span style="color:rgb(9, 78, 153)">DatabaseCleaner</span><strong>.</strong>strategy <strong>=</strong> <span style="color:rgb(139, 70, 127)">:transaction</span> <span style="color:rgb(9, 78, 153)">DatabaseCleaner</span><strong>.</strong>clean_with(<span style="color:rgb(139, 70, 127)">:truncation</span>) <strong>end</strong> config<strong>.</strong>around(<span style="color:rgb(139, 70, 127)">:each</span>) <strong>do</strong> <strong>|</strong>example<strong>|</strong> <span style="color:rgb(9, 78, 153)">DatabaseCleaner</span><strong>.</strong>cleaning <strong>do</strong> example<strong>.</strong>run <strong>end</strong> <strong>end</strong> <strong>end</strong> </pre><p>to:</p><pre><span style="color:rgb(9, 78, 153)">RSpec</span><strong>.</strong>configure <strong>do</strong> <strong>|</strong>config<strong>|</strong> config<strong>.</strong>before(<span style="color:rgb(139, 70, 127)">:suite</span>) <strong>do</strong> <span style="color:rgb(9, 78, 153)">DatabaseCleaner</span><strong>.</strong>strategy <strong>=</strong> <span style="color:rgb(139, 70, 127)">:transaction</span> <span style="color:rgb(9, 78, 153)">DatabaseCleaner</span><strong>.</strong>clean_with(<span style="color:rgb(139, 70, 127)">:truncation</span>) <strong>end</strong> config<strong>.</strong>around(<span style="color:rgb(139, 70, 127)">:each</span>) <strong>do</strong> <strong>|</strong>example<strong>|</strong> example<strong>.</strong>run <strong>end</strong> <strong>end</strong> </pre><p>I do not know a lot about the DatabaseCleaner gem, but this solved our initial persistence problem.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus