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"?
rspec speccommand should tell you which tests are pending. are you sure they are these? - x6iaerspec spec, I'd userspec 'spec/models/test_spec.rb' -fd. Then, once my unit test is passing, I'd do the full suite, integration testing, etc. BTW, the-fdgive you nice output formatting. - jvillianRSpec.describe Topic, type: :model do. Currently, you aren't telling RSpec that this is a model spec. - Michael Cruzrequire 'rails_helper'. And, I think you need to dobefore(:each) doorbefore(:all) doinstead of justbefore do. If this is not the entire file, then please post the whole thing. - jvillianbefore do, it is implicitly usingbefore(:each) do(at least with every version of RSpec I've personally used). Good catch on the missingrequire. - Michael Cruz