I believe I have some problem with scoping.
I have a controller spec file which tests a brands resource.
At the start of the file, I test the resource’s access for different
users in a context block
a) not signed in
b) non-admin user signed in- I call my own helper method, login_user
c) admin user signed in - I call my own helper method,
Specs there do pass successfully.
I then create another context block to just test the resource for an
admin user that’s signed in.
I tried calling login_admin_user in a before hook as per the previous
It fails and I suspect that the current scope within the before hook
does not see my custom helper method, login_admin_user.
Here is the error message:
--------- Extract start -----------------
load': /Users/anexiole/projects/ try_rails/spec/controllers/brands_controller_spec.rb:164: syntax error, unexpected keyword_end, expecting $end (SyntaxError) from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:inblock in load’
load_dependency' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:inload’
block in load_spec_files' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/configuration.rb:419:inmap’
load_spec_files' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/command_line.rb:18:inrun’
run_in_process' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/runner.rb:69:inrun’
rspec/core/runner.rb:11:in `block in autorun’
---------- Extract end ------------------
My specs is as follows:
--------- spec/controllers/brands_controller_spec.rb (start)
describe BrandsController do
This should return the minimal set of attributes required to
create a valid
Brand. As you add validations to Brand, be sure to
update the return value of this method accordingly.
‘name’ => ‘J Speed’,
‘description’ => ‘From gunsai province’
context 'checking access for varying users' do describe 'brands access is not available to users who have not
signed in’ do
it ‘users that are not logged in will be sent to the sign
in page’ do
describe 'brands access is not available to regular users' do login_user it 'regular users that are logged in will be sent to home
describe 'brands access is available only to admin users' do login_admin_user it 'admin users that are logged in can access the index
context 'with an admin user signed in' do # <----- starts
failing in this context
describe "creates a new brand entry" do it "assigns a new brand as @brand" do get :new assigns(:brand).should be_a_new(Brand) end end end
--------- spec/controllers/brands_controller_spec.rb (end)