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

How to test #67

Open
building39 opened this issue May 29, 2018 · 3 comments
Open

How to test #67

building39 opened this issue May 29, 2018 · 3 comments

Comments

@building39
Copy link

I have this test:


describe "RSpec matcher" do
  subject { User }

  it "should ensure that attributes are validated" do
    should validate_url_of(:homepage)
  end
end'''

It fails with `undefined method`:

```Run options: include {:locations=>{"./spec/models/xxx.rb"=>[3]}}
F

Failures:

  1) RSpec matcher should ensure that attributes are validated
     Failure/Error: should validate_url_of(:homepage)
     
     NoMethodError:
       undefined method `validate_url_of' for #<RSpec::ExampleGroups::RSpecMatcher:0x0000000138ed88>
     # ./spec/models/xxx.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00075 seconds (files took 0.0915 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/models/xxx.rb:6 # RSpec matcher should ensure that attributes are validated```

Clearly, I don't know what I'm doing. How can I get this test to work?

@kritik
Copy link
Member

kritik commented May 30, 2018

To be honest I don't know how to help you. Tests are passing and this gem is working in production. So, seems problem in your test

@Quintasan
Copy link
Contributor

For some reason I have the same problem.

My model:

class LawProposal < ApplicationRecord
  validates :name, presence: true
  validates :url, presence: true, url: { allow_nil: true }
end

My spec file:

require 'rails_helper'

RSpec.describe LawProposal, type: :model do
  subject { LawProposal.new }

  context "validations" do
    it "has a name" do
      expect(subject).not_to be_valid
    end

    it "has an url" do
      should validate_url_of(:url)
    end
  end
end

Error

Starting polikompas_gems_1 ... done
/usr/local/bin/ruby -I/gems/gems/rspec-core-3.8.0/lib:/gems/gems/rspec-support-3.8.0/lib /gems/gems/rspec-core-3.8.0/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

Randomized with seed 3592

LawProposal
  validations
    has a name
    has an url (FAILED - 1)

Failures:

  1) LawProposal validations has an url
     Failure/Error: should validate_url_of(:url)

     NoMethodError:
       undefined method `validate_url_of' for #<RSpec::ExampleGroups::LawProposal::Validations:0x000055843aa8e490>
     # ./spec/models/law_proposal_spec.rb:12:in `block (3 levels) in <top (required)>'

Finished in 0.09553 seconds (files took 2.2 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ./spec/models/law_proposal_spec.rb:11 # LawProposal validations has an url

@MothOnMars
Copy link
Contributor

Same issue here. I opened the above PR to resolve the issue.

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

4 participants