Rails Pro Tips from Rails core committer Aaron Patterson


Rails Pro Tips from Rails core committer Aaron Patterson

WHAT ARE THE PARTS OF RAILS?

Q: What are the components of Rails? Where do I find things?
A: The actionmailer directory contains the ActionMailer library code. It is in charge of sending out emails. If you need to deal with emails, look there.
The actionpack directory contains the ActionPack library. It is in charge of routing requests to the correct controller. It also contains the request and response class, as well as the controller base class that applications subclass.
The actionview directory contains the ActionView library. ActionView is in charge of templating. It contains logic for assembling HTML responses from templates.
The activerecord directory contains the ActiveRecord library. ActiveRecord is the ORM that ships with Rails. It is in charge of interfacing with the database, defining the schema inside Rails, etc. When you need to deal with data persistence, this is where you look.
The activemodel directory contains the ActiveModel library. ActiveModel is just an interface. ActiveRecord implements that interface. You shouldn't have to deal with ActiveModel much at all.
The activesupport directory contains the ActiveSupport library. ActiveSupport extends the Ruby language with things that make developing web applications easier. If you see a method that is non-standard Ruby, it is probably defined in ActiveSupport.
The railties directory contains "Railties". The code in here is in charge of tying together an application. It processes configuration, rake tasks, and managing startup of the application.

HOW DO I RUN TESTS?

Q: I would like to run all tests? How do I do that?
A: You can run rake test from the rails directory to run all tests. If you need to focus on ActionPack, just cd to the actionpack directory and run rake test. This is true for each component besides ActiveRecord.
Note from ESaaS staff: We will be using RSpec for our unit tests, so the correct task for our scenarios would be rake spec to run RSpec tests and rake features to run Cucumber scenarios.

HOW DO I RUN ACTIVERECORD TESTS?

Q: I would like to run the AR tests. How do I do that?
A: You can run all AR tests by running rake test, but this will run the tests for each database. If you want to run just the SQlite3 tests, do rake test_sqlite. If you want to run the mysql tests, do rake test_mysql, etc.

HOW DO I RUN JUST ONE TEST FILE?

Q: I would like to run just one file. How do I do that?
A: There are two ways to do it. One with just plain ruby like this:
ruby -I lib:test test/path/to/testfile.rb
The other is with rake like this:
rake test TEST=/test/path/to/testfile.rb
Note from ESaaS staff: We will be using RSpec for our unit tests, so the correct command line would be:rspec path/to/something_spec.rb

HOW DO I RUN JUST ONE TESTCASE?

Q: I would like to run just one file. How do I do that?
A: Provide the -n flag along with the method name, like this:
ruby -I lib:test test/path/to/testfile.rb -n test_sometest
or like this:
rake test TEST='/test/path/to/testfile.rb -n test_sometest'
Note from ESaaS staff: We will be using RSpec for our unit tests, so the correct command to run only the example(s) whose documentation string matches "Count my chickens" would be:rspec -e "should count my chickens" path/to/some_spec.rb
and the correct command to run only the example(s) beginning at line 79 of the test file would be:rspec -l 79 path/to/some_spec.rb


Source: edx online BerkleyX course (saas engineering cs169x.1)

Comments