Assigns_to not working for Rails 3 Shoulda on Ubuntu

I am using Rails3 with rspec and shoulda. I have the following specification

describe PagesController, "on GET to show while logged off" do
  before(:each) do
    @site = Factory.create(:site)
    @site.domains << Factory.create(:domain)
    @site.save!
    @site.pages << Factory.create(:page)
    @site.menus << Factory.create(:menu, {:site=>@site, :is_visible=>true})
    @site.menus << Factory.create(:menu, {:site=>@site, :is_visible=>true})
    @site.menus << Factory.create(:menu, {:is_visible=>false, :site=>@site})

    get :show
  end

  it { should render_template(:show) }
  it { should render_template('layouts/2col') }
  it { should assign_to(:site) }
  it { should assign_to(:site).with(@site) }
  it { should assign_to(:site).with(@site) }
  it { should assign_to(:page).with(@site.pages[0])}
  it "show visible menu_items only" do 
    assert assigns[:menu_items].length == 2
  end
end

Here is my gem file

group :development, :test do
  gem 'autotest'
  gem 'factory_girl'
  gem 'rspec', '>=2.0.0.beta.19'
  gem 'rspec-rails', '>=2.0.0.beta.17'
  gem 'shoulda'
end

and here is my spec_helper

require 'rspec/rails'
require 'shoulda'
require 'shoulda/integrations/rspec2'
require 'authlogic/test_case'
require 'factory_girl

Ok, so far, everything is pretty close to what I saw before, however, whenever I run my tests, I get errors, as shown below

1) PagesController on GET to show while logged off 
     Failure/Error: it { should assign_to(:site) }
     Expected action to assign a value for @site
     # ./spec/controllers/pages_controller_spec.rb:19

It was not my first thought that the code was broken, but the application is working properly. Also, if I check that the values ​​are assigned using the assignments [: site], then the test passes.

Does anyone know what I need to change for these tests to start working again.

Thanks in advance

Andy

+3
source share
2 answers

subject { controller } it. , .

+3

Ruby 1.9.2, assign_to gem shoulda-matchers 1.0.0beta2 , subject { controller } (, , ).

Ruby 1.9.2. bugreport shoulda. shoulda-matchers 1.0.0beta2.

, Gemfile:

group :development, :test do
  gem 'shoulda-matchers'
  ...    

(1.0.0.beta2 atm):

bundle update shoulda-matchers
0

Source: https://habr.com/ru/post/1765535/


All Articles