My folder structure is as follows: /myapp/ /myapp/lib/class1.rb /myapp/rspec/spec_helper.rb /myapp/rspec/lib/class1_spec.rb My spec_helper has: require ''rubygems'' require ''rspec'' RSpec.configure do |config| end My class1_spec.rb has: require ''spec_helper'' require ''../../lib/class1'' describe Class1 do it "should do something" end How do I require my class1 correct, when I run: rspec spec/lib/class1_spec.rb I am getting: 1.9.1/rubygems/custom_require.rb:36:in `require'': cannot load such file -- ../../lib/class1.rb (LoadError) Also, in a non-rails app, what kind of things do you put in the spec_helper normally? any popular config settings that I should know about? thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120423/08eab308/attachment.html>
David Chelimsky
2012-Apr-23 17:42 UTC
[rspec-users] using rspec in a non-rails environment
On Mon, Apr 23, 2012 at 12:26 PM, S Ahmed <sahmed1020 at gmail.com> wrote:> My folder structure is as follows: > > /myapp/ > /myapp/lib/class1.rb > > /myapp/rspec/spec_helper.rb > /myapp/rspec/lib/class1_spec.rb > > My spec_helper has: > > require ''rubygems''^^ If you''ve installed rspec as a gem and you''re running the rspec command, you don''t need to require ''rubygems''. ^^> require ''rspec''^^ This should be ''rspec/autorun''. ^^> > RSpec.configure do |config| > endThis ^^ is not necessary unless you''re using it> My class1_spec.rb has: > > require ''spec_helper'' > require ''../../lib/class1'' > > describe Class1 do > ? it "should do something" > end > > > How do I require my class1 correct, when I run: > > rspec spec/lib/class1_spec.rb I am getting: > > 1.9.1/rubygems/custom_require.rb:36:in `require'': cannot load such file -- > ../../lib/class1.rb (LoadError)RSpec adds ''lib'' to the LOAD_PATH, so you can just `require "class1"`, but it''s conventional to do this in spec_helper.rb instead. HTH, David> Also, in a non-rails app, what kind of things do you put in the spec_helper > normally? any popular config settings that I should know about? > > thanks!
ok have to lookup what rspec/autorun does as oppose to just ''require "rspec"'' thanks, it is now working :) feels good! I''ve always been tied to rails, seems like I was spoiled and not sure how to do basic things in ruby.... On Mon, Apr 23, 2012 at 1:42 PM, David Chelimsky <dchelimsky at gmail.com>wrote:> On Mon, Apr 23, 2012 at 12:26 PM, S Ahmed <sahmed1020 at gmail.com> wrote: > > My folder structure is as follows: > > > > /myapp/ > > /myapp/lib/class1.rb > > > > /myapp/rspec/spec_helper.rb > > /myapp/rspec/lib/class1_spec.rb > > > > My spec_helper has: > > > > require ''rubygems'' > > ^^ If you''ve installed rspec as a gem and you''re running the rspec > command, you don''t need to require ''rubygems''. ^^ > > > require ''rspec'' > > ^^ This should be ''rspec/autorun''. ^^ > > > > > RSpec.configure do |config| > > end > > This ^^ is not necessary unless you''re using it > > > My class1_spec.rb has: > > > > require ''spec_helper'' > > require ''../../lib/class1'' > > > > describe Class1 do > > it "should do something" > > end > > > > > > How do I require my class1 correct, when I run: > > > > rspec spec/lib/class1_spec.rb I am getting: > > > > 1.9.1/rubygems/custom_require.rb:36:in `require'': cannot load such file > -- > > ../../lib/class1.rb (LoadError) > > RSpec adds ''lib'' to the LOAD_PATH, so you can just `require "class1"`, > but it''s conventional to do this in spec_helper.rb instead. > > HTH, > David > > > > Also, in a non-rails app, what kind of things do you put in the > spec_helper > > normally? any popular config settings that I should know about? > > > > thanks! > _______________________________________________ > 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/20120423/77744a63/attachment.html>