Don't generate request or routing specs when using generators #168

Closed
wants to merge 6 commits into
from

Projects

None yet

3 participants

@geoffharcourt
Contributor

I want to suggest not generating routing or request specs when using app generators. The request specs are nearly useless, and routing specs are better handled using shoulda matchers within controller specs.

geoffharcourt added some commits Mar 8, 2013
@geoffharcourt geoffharcourt Include factory_girl_rails in development enrivonment in addition to …
…test

Including FactoryGirl in the development environment ensures that
factories get created when default generators are used. Adding
FactoryGirl to development also provides factory functionality when in
the development console.
c3df4c5
@geoffharcourt geoffharcourt Use more verbose factories_spec.rb
Code from thoughtbot factory_girl wiki for testing that factories are
producting valid models. See issue #123.
bb14cdf
@geoffharcourt geoffharcourt Use expect form for RSpec when validating factories. 264a7b7
@geoffharcourt geoffharcourt Don't generate request or routing specs when using generators. ef67f97
@croaky croaky and 1 other commented on an outdated diff Apr 8, 2013
templates/factories_spec.rb
@@ -1,9 +1,14 @@
require 'spec_helper'
-FactoryGirl.factories.map(&:name).each do |factory_name|
- describe "the #{factory_name} factory" do
- it 'is valid' do
- expect(build(factory_name)).to be_valid
+describe 'validate FactoryGirl factories' do
+ FactoryGirl.factories.each do |factory|
+ context "with factory for :#{factory.name}" do
+ subject { FactoryGirl.build(factory.name) }
+
+ it "is valid" do
+ is_valid = subject.valid?
+ expect(is_valid).to be_true, subject.errors.full_messages.join(',')
@croaky
croaky Apr 8, 2013 Member

Could this be expect(subject).to be_valid?

@geoffharcourt
geoffharcourt Apr 27, 2013 Contributor

Yes. Let me update that and fix.

@croaky croaky commented on an outdated diff Apr 8, 2013
templates/factories_spec.rb
@@ -1,9 +1,14 @@
require 'spec_helper'
-FactoryGirl.factories.map(&:name).each do |factory_name|
- describe "the #{factory_name} factory" do
- it 'is valid' do
- expect(build(factory_name)).to be_valid
+describe 'validate FactoryGirl factories' do
+ FactoryGirl.factories.each do |factory|
+ context "with factory for :#{factory.name}" do
+ subject { FactoryGirl.build(factory.name) }
@croaky
croaky Apr 8, 2013 Member

Does the build syntax work here?

@harlow harlow and 1 other commented on an outdated diff Apr 8, 2013
templates/factories_spec.rb
end
end
-end
+end
@harlow
harlow Apr 8, 2013 Contributor

Watch for no newline at end of file too. If using Sublime this can be updated in the settings.

@geoffharcourt
geoffharcourt Apr 27, 2013 Contributor

Thanks, and apologies for that. Remedying in the next commit.

geoffharcourt added some commits Apr 27, 2013
@geoffharcourt geoffharcourt Add back newline to end of file
Added newline to end of file to comply with style guidelines.

thoughtbot#168 (comment)
529ecc6
@geoffharcourt geoffharcourt Use be_valid matcher, avoid use of subject
Using be_valid matcher rather than awkward be_true check on
model#valid?. Refactored to avoid explicit use of subject.
6329c53
@croaky
Member
croaky commented Jul 14, 2013

Sorry for the delay on this, @geoffharcourt. I've updated the commit to just focus on the generators as the other changes (factories spec, factory_girl_rails in development/test environments) have since been addressed.

Merged as 11f4401. Thanks!

@croaky croaky closed this Jul 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment