Comments (10)
Rails itself doesn't document assert_raise
in their testing guides https://guides.rubyonrails.org/testing.html
The alias itself was added 12 years ago and marked as for backwards compatibility reasons rails/rails@aa7857b, apparently from before rails was using minitest.
from rails-style-guide.
I'm not sure whether assert_raises
or assert_raise
is preferable as the default. Please discuss it in the style guide first.
from rails-style-guide.
assert_raise
is an alias for Rails' own assert_raises
, which adds support for a match
parameter, so it's not Minitest's assert_raises
:
But I would support a guideline to prefer assert_raises
over assert_raise
for consistency.
from rails-style-guide.
rubocop/rubocop-rails#913 might be added for background context.
from rails-style-guide.
For example, in the rails/rails
repository, both assert_raise
and assert_raises
are used. If the Rails development team has a consistent preference for assert_raises
, I feel it should be respected. e.g.
Use
assert_not
methods instead ofrefute
.
https://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions
But, I'm not sure what the actual situation is.
from rails-style-guide.
Well, rails doesn't accept cosmetic changes. If someone where to come along wanting to change it the pr would just be rejected.
Is there something which collects rails applications like https://github.com/eliotsykes/real-world-rails? I have seen this repo come up in the past but it hasn't been maintained for the last few years.
from rails-style-guide.
The Ruby API itself is primarily named using the base form of verbs. For instance, in Ruby 3.2, File.exists
was removed, leaving only File.exist
. Given this, some might prefer assert_raise
over assert_raises
.
from rails-style-guide.
That does indeed seem to be the prefered way for the ruby project itself. ruby/ruby@068f312 ruby/ruby@f159bbd
A code search on github for assert_raise
and assert_raises
also reveals that assert_raise
has more usages than I would have expected:
assert_raises: 14k + 10.4k
assert_raise: 7.9k + 5.2k
Per these numbers assert_raises
is used about twice as often as assert_raise
. But then again these searches also include projects that don't use Rails. I don't think you're able to query for rails specifically, or get the numbers of actual matches instead of the amount of times the query appears in a file.
Personally I would still go with assert_raises
since that is the method defined by minitest. But it looks like if this cop would be implemented there needs to be a config option so you're able to go with the variant you prefer.
from rails-style-guide.
When implementing a cop, default is important for users. Respecting Ruby's API naming and choosing assert_raise
seems better, but the best choice remains uncertain.
from rails-style-guide.
When implementing cops, is there precedence for disabled by default and a required config key? Early adopters could opt in and must set their prefered style explicitly.
It's not obvious which variant is better but I'd still like to try and work on this since it'll eventually go one way or another. If/When a conclusion is reached the config can be changed.
from rails-style-guide.
Related Issues (20)
- 7 Standard Controller Actions HOT 11
- Use more specific predicates instead of vague `blank?` and `present?` HOT 2
- Per attribute validations
- Prefer `ActionDispatch::IntegrationTest` over `ActionController::TestCase`
- Better docs for `dependent: :destroy` HOT 1
- Where with Ranges: "good" vs "bad" are not equivalent HOT 3
- Description of Single Attribute Validations seems wrong. HOT 1
- Suggestion: Avoid `render ... and return` HOT 4
- Suggestion: Use string literals instead of named routes or URL helpers in tests HOT 2
- Add delete_all to the list of methods that skip model validations HOT 2
- Cop idea: prefer symbol proc to `if:` and `unless:` filter lambdas HOT 2
- Are blank routes preferred or routes with `/`
- Suggestion: Add notes about `.none()` HOT 1
- Suggestion: Add notes about returned value of ActiveRecord transaction
- Suggestion: Add description about Active Record redundant `all` HOT 1
- Suggestion: don't divide `.where.not` into two lines
- Suggestion: 3-state booleans don't require a default HOT 3
- "Redundant `all`" is too naive HOT 10
- Cop idea: merge `.first` || `.create!` into `.first_or_create!` HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails-style-guide.