`<main>': uninitialized constant RSpec (NameError) using when testing Ruby files -


i've looked @ several posts regarding issue , can't seem find fix it. i'm working through assignment in ruby on rails dev course , we've hit module on tdd/bdd rspec. i've had success far cannot figure out error:

<main>': uninitialized constant rspec (nameerror)

i have gone through expectations , code line line ensure it's correct. rspec capitalized in spec file, have class corresponding end typically cause rspec throw error. i'm still learning rspec, though. working on last expectation statement when error started popping up.

code

require_relative "entry.rb"  class addressbook attr_accessor :entries    def initialize    @entries = []   end    def add_entry(name, phone, email)    index = 0    @entries.each |entry|       if name < entry.name        break       end       index += 1      end     @entries.insert(index, entry.new(name, phone, email))   end    def remove_entry    end end 

rspec

rspec.describe addressbook      context "attributes"      "should respond entries"        book = addressbook.new        expect(book).to respond_to(:entries)      end       "should initialize entries array"        book = addressbook.new        expect(book.entries).to be_a(array)      end       "should initialize entries empty"        book = addressbook.new        expect(book.entries.size).eql? 0      end    end     context ".add_entry"      "adds 1 entry address book"         book = addressbook.new             book.add_entry('ada lovelace', '010.012.1815', 'augusta.king@lovelace.com')          expect(book.entries.size).eql? 1      end       "adds correct information entries"        book = addressbook.new             book.add_entry('ada lovelace', '010.012.1815', 'augusta.king@lovelace.com')        new_entry = book.entries[0]         expect(new_entry.name).eql? 'ada lovelace'        expect(new_entry.phone_number).eql? '010.012.1815'        expect(new_entry.email).eql? 'augusta.king@lovelace.com'      end    end      "removes 1 entry address book"      book = addressbook.new      expect(book.entries.size).to change.by(1)   end  end 

update

i ran rspec spec/address_book_specs.rb answer stated below , received following:

/users/jrshafer/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in     `require': cannot load such file -- spec_helper.rb (loaderror)     /users/jrshafer/.rvm/rubies/ruby-    2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in     `require'     /users/jrshafer/bloc/code/address-bloc/spec/address_book_specs.rb:1:in `<top (required)>'     /users/jrshafer/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `load'     /users/jrshafer/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'     /users/jrshafer/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `each'     /users/jrshafer/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `load_spec_files'     /users/jrshafer/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:97:in `setup'     /users/jrshafer/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:85:in `run'     /users/jrshafer/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'     /users/jrshafer/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'     /users/jrshafer/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.2.3/exe/rspec:4:in `<top (required)>'     /users/jrshafer/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `load'     /users/jrshafer/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `<main>'     /users/jrshafer/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'     /users/jrshafer/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>' 

i swear had absolutely no problems running tests before. i've started project on since wasn't far , i'm having same issue.

your file specs should require spec_helper, , file class you're testing:

require "spec_helper" require_relative "../../lib/address_book" # please update accordingly  rspec.describe addressbook     context "attributes"     "should respond entries"       book = addressbook.new       expect(book).to respond_to(:entries)   end   # ... end 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -