0
votes

I'm creating a Rails app and just added a file (app/spec/models/test_spec.rb )with 5 new rspec tests:

describe Topic do
   describe "scopes" do

     before do 
       @public_topic = Topic.create # default is public
       @private_topic = Topic.create(public: false)
     end

     describe "publicly_viewable" do
       it "returns a relation of all public topics" do
         expect(Topic.publicly_viewable).to eq( [@public_topic] )
       end
     end

     describe "privately_viewable" do
       it "returns a relation of all private topics" do
         expect(Topic.privately_viewable).to eq( [@private_topic] )
       end
     end

     describe "visible_to(user)" do
       it "returns all topics if the user is present" do
         user = User.new
         expect(Topic.visible_to(user)).to eq(Topic.all)
       end

       it "returns only public topics if user is nil" do
         expect(Topic.visible_to(nil)).to eq(Topic.publicly_viewable)
       end
     end
  end
end

When I ran "rspec spec" in the console, I got the following output:

Finished in 8.38 seconds (files took 1 minute 40.84 seconds to load) 18 examples, 1 failure, 5 pending

Why are these 5 examples "pending"?

1
the rspec spec command should tell you which tests are pending. are you sure they are these? - x6iae
Also, for what it's worth, while I'm working on a particular piece of functionality, I like to run only the unit test for that piece. So instead of rspec spec, I'd use rspec 'spec/models/test_spec.rb' -fd. Then, once my unit test is passing, I'd do the full suite, integration testing, etc. BTW, the -fd give you nice output formatting. - jvillian
Try changing your first line there to RSpec.describe Topic, type: :model do. Currently, you aren't telling RSpec that this is a model spec. - Michael Cruz
Also, is this your actual spec file? You're missing require 'rails_helper'. And, I think you need to do before(:each) do or before(:all) do instead of just before do. If this is not the entire file, then please post the whole thing. - jvillian
@jvillian - when using before do, it is implicitly using before(:each) do (at least with every version of RSpec I've personally used). Good catch on the missing require. - Michael Cruz

1 Answers

1
votes

Rspec automatically creates specs for you in other sub-directories of spec/. You are running the spec on the whole spec/ directory, which includes the auto-generated controller specs, view specs, route specs, etc. These come with pending examples. If you only want to run the specs in this file, run rspec spec/models/test_spec.rb