Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rspec 3 Expect Syntax for be_a_closure_tree #110

Closed
jhephs opened this issue Jul 3, 2014 · 10 comments
Closed

Rspec 3 Expect Syntax for be_a_closure_tree #110

jhephs opened this issue Jul 3, 2014 · 10 comments

Comments

@jhephs
Copy link

jhephs commented Jul 3, 2014

There seems to be a problem when I'm using the indicated matcher in the README.

The error states the following:

1) Category should be a closure tree
     Failure/Error: it { is_expected.to be_a_closure_tree }
       expected #<Category:0x00000102623150> to respond to `closure_tree?`
@seuros
Copy link
Member

seuros commented Jul 3, 2014

Did you add require 'closure_tree/test/matcher' to your (rails_helper | spec_helper) ?

@jhephs
Copy link
Author

jhephs commented Jul 3, 2014

Yes I did. I put it inside rails_helper.rb after the following lines:

ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)

@seuros
Copy link
Member

seuros commented Jul 3, 2014

Add this in the bottom

RSpec.configure do |c|
  c.include ClosureTree::Test::Matcher, type: :model
end

I will send PR to fix that, you can remove this after @mceachen release a new version. Sorry.

@jhephs
Copy link
Author

jhephs commented Jul 3, 2014

It seems to have fixed the previous error but there is now a new error. Please check.

Failure/Error: it { is_expected.to be_a_closure_tree }
     NoMethodError:
       undefined method `column_names' for #<Category:0x00000107059170>

@seuros
Copy link
Member

seuros commented Jul 3, 2014

is Category an activerecord model ?
if you can If you can gist your model and the spec, that will help me locate the problem

@jhephs
Copy link
Author

jhephs commented Jul 3, 2014

Yes, it is.

Here is the model and its corresponding spec:

# category.rb
class Category < ActiveRecord::Base

  acts_as_tree

  validates :name, :presence => true

  scope :has_children, -> { joins(:children).uniq }

end

# category_spec.rb
require 'rails_helper'

RSpec.describe Category, :type => :model do

  it { is_expected.to validate_presence_of(:name) }

  it { is_expected.to be_a_closure_tree }

end

@seuros
Copy link
Member

seuros commented Jul 3, 2014

What version of rails do you use ?
Can you run this in console the Category.column_names ?

@jhephs
Copy link
Author

jhephs commented Jul 3, 2014

I'm currently using Rails 4.1.2.rc2

2.1.2 :014 > Category.column_names
 => ["id", "name", "href", "parent_id", "created_at", "updated_at"]

I think the problem here is that the default subject for a model spec is an instance of the class?

@seuros
Copy link
Member

seuros commented Jul 3, 2014

You are totally right.
A workaround will be expect(Category).to be be_a_closure_tree .
I will send a PR to fix that, you will be able to use the Readme syntax in the next version.

Thank you!

@jhephs
Copy link
Author

jhephs commented Jul 3, 2014

Thanks!! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants