Witam,
chciałem dzisiaj się zając rspec i niestety jako to najczęściej bywa mam problem :D.
oto co zrobiłem do tej pory
- dodałem gem ‘rspec’
- bundle install
- rspec --init
- mkdir spec/models
w models mam plik user_spec.rb który zawiera coś takiego
[code]require ‘spec_helper’
describe User do
it “has a email” do
User.new.should respond_to :email
end
it “has a name” do
User.new.should respond_to :name
end
end[/code]
po wykonaniu komendy rspec dostaje takie błędy.
/home/patryk/projekt1/spec/models/user_spec.rb:3:in `<top (required)>': uninitialized constant User (NameError)
from /home/patryk/.rvm/gems/ruby-1.9.3-p374@projekt1/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load'
from /home/patryk/.rvm/gems/ruby-1.9.3-p374@projekt1/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /home/patryk/.rvm/gems/ruby-1.9.3-p374@projekt1/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `each'
from /home/patryk/.rvm/gems/ruby-1.9.3-p374@projekt1/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /home/patryk/.rvm/gems/ruby-1.9.3-p374@projekt1/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:22:in `run'
from /home/patryk/.rvm/gems/ruby-1.9.3-p374@projekt1/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in `run'
from /home/patryk/.rvm/gems/ruby-1.9.3-p374@projekt1/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'
a i jeszcze spec_helper,rb
[code]# This file was generated by the rspec --init
command. Conventionally, all
specs live under a spec
directory, which RSpec adds to the $LOAD_PATH
.
Require this file using require "spec_helper"
to ensure that it is only
loaded once.
See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
Run specs in random order to surface order dependencies. If you find an
order dependency and want to debug it, you can fix the order by providing
the seed, which is printed after each run.
–seed 1234
config.order = ‘random’
end[/code]
pytanie dlaczego nie widzi modelu? czy muszę gdzieś to ustawić w configu? Komende wykonuje będąc w katalogu głównym aplikacji poprzedzając to rvm use 1.9.3@projekt1
Z góry dzięki za pomoc