Giter VIP home page Giter VIP logo

Comments (1)

crawfoal avatar crawfoal commented on August 22, 2024

I've eliminated all of the before :each hooks that were setting up roles by using a before :suite hook for this. For this to work, I had to make sure that the roles were defined after database_cleaner truncated all existing table in the before :suite hook in rails_helper.rb (I just called define_roles below their call to truncation in there). Additionally, when truncation is used for the capybara javascript examples, it needs to be set up to not truncate the roles table. So here are the important changes:

# rails_helper.rb
...
config.before(:suite) do
  ...
  DatabaseCleaner.clean_with(:truncation) # this line truncates all tables before the test suite runs
  define_roles(:setter,:athlete) # make sure this table is created after line above runs
end
config.before(:each) do
  ...
  DatabaseCleaner.strategy = :truncation, {except: %w[roles]}
end
...

Some people might argue that it is bad to have any data setup for the entire test suite like this. I don't fully understand their argument, so I might change my mind about this later, but for now I think it is okay because when I test the actual role model itself, I don't use the :athlete and :setter roles, I use dummy roles that have no special meaning in my application (e.g. :some_role).

Also, I've left all hooks that set up stubs/mocks, and hooks that run http requests. I think the stubs and mocks can't be setup in before :all hooks. For the before hooks that run http requests, I think they are better as shared contexts, but I need to read more about that.

from climbalytics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.