Hello, Is there any way to reuse spec definitions, perhaps through some kind of inheritance? For example, in rails, every time it generates a Spec I must tell it to 1) Include Devise::TestHelpers 2) Log the user in, so there is a default user setup before each test is run. This is common for 95% of my controllers and doesn''t seem very DRY to me. 3) Other types of things that end up requiring setup In Java (my main language), I could put all of this in a base class and just extend it... but I don''t know how to do that with a describe block. Is there a mechanism for dealing with this? Do I need to include a module that includes the devise helpers and whatever else I need it to do? Thanks Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110518/4b375a7e/attachment.html>
On May 18, 2011, at 11:23 AM, Ken Egervari wrote:> Hello, > > Is there any way to reuse spec definitions, perhaps through some kind of inheritance? > > For example, in rails, every time it generates a Spec I must tell it to > > 1) Include Devise::TestHelpers > 2) Log the user in, so there is a default user setup before each test is run. This is common for 95% of my controllers and doesn''t seem very DRY to me. > 3) Other types of things that end up requiring setup > > In Java (my main language), I could put all of this in a base class and just extend it... but I don''t know how to do that with a describe block. > > Is there a mechanism for dealing with this? Do I need to include a module that includes the devise helpers and whatever else I need it to do?Take a look at shared context: http://relishapp.com/rspec/rspec-core/dir/example-groups/shared-context
On Wed, May 18, 2011 at 10:23 AM, Ken Egervari <ken.egervari at gmail.com>wrote:> Hello, > > Is there any way to reuse spec definitions, perhaps through some kind of > inheritance? > > For example, in rails, every time it generates a Spec I must tell it to > > 1) Include Devise::TestHelpers >you can do: RSpec.configuration do |config| config.include Devise::TestHelpers, :type => :controller end This will include it in all of your controllers.> 2) Log the user in, so there is a default user setup before each test is > run. This is common for 95% of my controllers and doesn''t seem very DRY to > me. > 3) Other types of things that end up requiring setup > > In Java (my main language), I could put all of this in a base class and > just extend it... but I don''t know how to do that with a describe block. > > Is there a mechanism for dealing with this? Do I need to include a module > that includes the devise helpers and whatever else I need it to do? > > Thanks > > Ken > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110518/2f3259f5/attachment.html>
Hi Justin I tried that config.include call in my test.rb file, but Rails complains:: /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/railtie/configuration.rb:77:in `method_missing'': undefined method `include'' for #<Rails::Application::Configuration:0x000000027b3098> (NoMethodError) from /home/egervari/Projects/training/config/environments/test.rb:36:in `block in <top (required)>'' I am using Rails 3.0.7 I hope we can get this to work because that would solve part of this problem. Then I can look at shared state to log the user in and other things. Ken On Wed, May 18, 2011 at 4:06 PM, Justin Ko <jko170 at gmail.com> wrote:> > > On Wed, May 18, 2011 at 10:23 AM, Ken Egervari <ken.egervari at gmail.com>wrote: > >> Hello, >> >> Is there any way to reuse spec definitions, perhaps through some kind of >> inheritance? >> >> For example, in rails, every time it generates a Spec I must tell it to >> >> 1) Include Devise::TestHelpers >> > > you can do: > > RSpec.configuration do |config| > config.include Devise::TestHelpers, :type => :controller > end > > This will include it in all of your controllers. > > >> 2) Log the user in, so there is a default user setup before each test is >> run. This is common for 95% of my controllers and doesn''t seem very DRY to >> me. >> 3) Other types of things that end up requiring setup >> >> In Java (my main language), I could put all of this in a base class and >> just extend it... but I don''t know how to do that with a describe block. >> >> Is there a mechanism for dealing with this? Do I need to include a module >> that includes the devise helpers and whatever else I need it to do? >> >> Thanks >> >> Ken >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110518/8ba19504/attachment.html>
On Wed, May 18, 2011 at 8:33 PM, Ken Egervari <ken.egervari at gmail.com>wrote:> Hi Justin > > I tried that config.include call in my test.rb file, but Rails complains:: > > /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/railtie/configuration.rb:77:in > `method_missing'': undefined method `include'' for > #<Rails::Application::Configuration:0x000000027b3098> (NoMethodError) > from /home/egervari/Projects/training/config/environments/test.rb:36:in > `block in <top (required)>'' > > I am using Rails 3.0.7 > > I hope we can get this to work because that would solve part of this > problem. Then I can look at shared state to log the user in and other > things. > > Ken > > > > On Wed, May 18, 2011 at 4:06 PM, Justin Ko <jko170 at gmail.com> wrote: > >> >> >> On Wed, May 18, 2011 at 10:23 AM, Ken Egervari <ken.egervari at gmail.com>wrote: >> >>> Hello, >>> >>> Is there any way to reuse spec definitions, perhaps through some kind of >>> inheritance? >>> >>> For example, in rails, every time it generates a Spec I must tell it to >>> >>> 1) Include Devise::TestHelpers >>> >> >> you can do: >> >> RSpec.configuration do |config| >> config.include Devise::TestHelpers, :type => :controller >> end >> >> This will include it in all of your controllers. >> >> >>> 2) Log the user in, so there is a default user setup before each test is >>> run. This is common for 95% of my controllers and doesn''t seem very DRY to >>> me. >>> 3) Other types of things that end up requiring setup >>> >>> In Java (my main language), I could put all of this in a base class and >>> just extend it... but I don''t know how to do that with a describe block. >>> >>> Is there a mechanism for dealing with this? Do I need to include a module >>> that includes the devise helpers and whatever else I need it to do? >>> >>> Thanks >>> >>> Ken >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >Woops! It needs to go in your spec/spec_helper.rb file, not your test.rb environment file. Also, I would upgrade to Ruby 1.9.2 - 1.9.1 has some bugs that will give you problems. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110518/7ee13172/attachment-0001.html>
Oh, never mind. I tried this in spec_helper.rb and it works ;) Ken On Wed, May 18, 2011 at 9:33 PM, Ken Egervari <ken.egervari at gmail.com>wrote:> Hi Justin > > I tried that config.include call in my test.rb file, but Rails complains:: > > /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/railtie/configuration.rb:77:in > `method_missing'': undefined method `include'' for > #<Rails::Application::Configuration:0x000000027b3098> (NoMethodError) > from /home/egervari/Projects/training/config/environments/test.rb:36:in > `block in <top (required)>'' > > I am using Rails 3.0.7 > > I hope we can get this to work because that would solve part of this > problem. Then I can look at shared state to log the user in and other > things. > > Ken > > > > On Wed, May 18, 2011 at 4:06 PM, Justin Ko <jko170 at gmail.com> wrote: > >> >> >> On Wed, May 18, 2011 at 10:23 AM, Ken Egervari <ken.egervari at gmail.com>wrote: >> >>> Hello, >>> >>> Is there any way to reuse spec definitions, perhaps through some kind of >>> inheritance? >>> >>> For example, in rails, every time it generates a Spec I must tell it to >>> >>> 1) Include Devise::TestHelpers >>> >> >> you can do: >> >> RSpec.configuration do |config| >> config.include Devise::TestHelpers, :type => :controller >> end >> >> This will include it in all of your controllers. >> >> >>> 2) Log the user in, so there is a default user setup before each test is >>> run. This is common for 95% of my controllers and doesn''t seem very DRY to >>> me. >>> 3) Other types of things that end up requiring setup >>> >>> In Java (my main language), I could put all of this in a base class and >>> just extend it... but I don''t know how to do that with a describe block. >>> >>> Is there a mechanism for dealing with this? Do I need to include a module >>> that includes the devise helpers and whatever else I need it to do? >>> >>> Thanks >>> >>> Ken >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110518/af68f23d/attachment.html>
Thanks strange... I have installed Ruby 1.9.2 and that''s what comes up in the command line: egervari at egervari:~/Projects/training$ ruby --version ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux] However, you''re right... RubyMine seems to be using 1.9.1. Thanks for the catch! I think it''s because Ubuntu has installed 1.9.1 as a package and Idea detected this one over the the other one. Ken On Wed, May 18, 2011 at 9:36 PM, Justin Ko <jko170 at gmail.com> wrote:> > > On Wed, May 18, 2011 at 8:33 PM, Ken Egervari <ken.egervari at gmail.com>wrote: > >> Hi Justin >> >> I tried that config.include call in my test.rb file, but Rails complains:: >> >> /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/railtie/configuration.rb:77:in >> `method_missing'': undefined method `include'' for >> #<Rails::Application::Configuration:0x000000027b3098> (NoMethodError) >> from >> /home/egervari/Projects/training/config/environments/test.rb:36:in `block in >> <top (required)>'' >> >> I am using Rails 3.0.7 >> >> I hope we can get this to work because that would solve part of this >> problem. Then I can look at shared state to log the user in and other >> things. >> >> Ken >> >> >> >> On Wed, May 18, 2011 at 4:06 PM, Justin Ko <jko170 at gmail.com> wrote: >> >>> >>> >>> On Wed, May 18, 2011 at 10:23 AM, Ken Egervari <ken.egervari at gmail.com>wrote: >>> >>>> Hello, >>>> >>>> Is there any way to reuse spec definitions, perhaps through some kind of >>>> inheritance? >>>> >>>> For example, in rails, every time it generates a Spec I must tell it to >>>> >>>> 1) Include Devise::TestHelpers >>>> >>> >>> you can do: >>> >>> RSpec.configuration do |config| >>> config.include Devise::TestHelpers, :type => :controller >>> end >>> >>> This will include it in all of your controllers. >>> >>> >>>> 2) Log the user in, so there is a default user setup before each test is >>>> run. This is common for 95% of my controllers and doesn''t seem very DRY to >>>> me. >>>> 3) Other types of things that end up requiring setup >>>> >>>> In Java (my main language), I could put all of this in a base class and >>>> just extend it... but I don''t know how to do that with a describe block. >>>> >>>> Is there a mechanism for dealing with this? Do I need to include a >>>> module that includes the devise helpers and whatever else I need it to do? >>>> >>>> Thanks >>>> >>>> Ken >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > Woops! It needs to go in your spec/spec_helper.rb file, not your test.rb > environment file. > > Also, I would upgrade to Ruby 1.9.2 - 1.9.1 has some bugs that will give > you problems. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110518/fc745a11/attachment.html>