I have the following line set in spec_helper.rb
config.use_transactional_fixtures = true
This means that every test should cleanup after itself. Any db update made by one test should not be around for the next test.
I have two tests in one of my spec files.
it 'should update the DB' do
Setting.put('abcd', 'efgh')
end
it 'should not find the DB update' do
Setting.get('abcd').should be_nil
end
The above two test used to work with Rails 3.2.14
However after upgrading to Rails 4, the second test fails with the following error,
------
expected: nil
got: "efgh"
-----
I have about a 100 tests failing in the suite because of this issue.
The only related documentation I can find for Rails 4 upgrade was something quite vague: "Rails 4.0 has deprecated ActiveRecord::Fixtures in favor of ActiveRecord::FixtureSet."
I am not sure if/how this is relevant. I would ideally like to have a global setting (config.use_transactional_fixtures = true), and not have to change the logic of the tests (or add extra before(:each)/after(:each) modules just to get existing tests to pass. Please help!
I am not sure, that it's same problem. But for me the solution was - to create data only in "it" do/end block. And if you create data in context it doesn't work.
that's works:
context "with array of both exista and non exist words" do
clean_words = ["foo", "bar", "foobar"]
language = "eng"
it "return array of word, that exist in Word class" do
word = FactoryGirl.create(:word)
word2 = FactoryGirl.create(:word, name: "bar")
exist_words = [word, word2]
expect(Word.generate_list_of_exist_words(clean_words, language).sort).to eq exist_words.sort
end
end
that's not works:
context "with array of both exista and non exist words" do
clean_words = ["foo", "bar", "foobar"]
word = FactoryGirl.create(:word)
word2 = FactoryGirl.create(:word, name: "bar")
exist_words = [word, word2]
language = "eng"
it "return array of word, that exist in Word class" do
expect(Word.generate_list_of_exist_words(clean_words, language).sort).to eq exist_words.sort
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With