ruby-on-rails,regex,rspec,shoulda
I think you using invalid validation helper i.e. validate instead of validates.
The rspec error comes from this line account = create(:account, :empty), not this one account.should_not be_valid create will attempt to create the record in the database, and go through the validation. use build instead...
ruby-on-rails,ruby,rspec,shoulda
I think strict validators are tested like this: describe Thing do subject(:thing) { FactoryGirl.build_stubbed :thing } it { should validate_presence_of(:status).strict } end ...
I'm not entirely confident of this answer in the sense that there may be alternate/simpler ways of approaching this, but here's my understanding: I think it's just a regular RSpec "matcher" that you are seeking here. shoulda is a gem containing a particular set of matchers. You need to pass...
ruby-on-rails,testing,rspec,controller,shoulda
You forgot the id before { get :show, id: 1 } # Assuming there is a Restaurant with id=1 ...
ruby-on-rails,ruby-on-rails-4,rspec,factory-girl,shoulda
I would just test the methods normally, not even worrying that they will be used as callbacks. That means establish a known state, perform your operation, and check for the desired state, for each one. Then, you can use something like shoulda-callback-matchers to verify that the proper callbacks are actually...
This ended up being a simple fix. I just needed to add a subdomain constraint in the #to method and ensure the #route method had the full url: module API module V1 class RoutingTest < ActionController::TestCase should route(:get, 'http://api.example.com/v1') .to('api/v1/data#index', subdomain: 'api', format: :json) ... Or, if you are in...
ruby-on-rails,validation,mongoid,shoulda
Judging by the error message, it seems you have also installed mongoid-rspec gem which is also defining validates_inclusion_of method. In your case it is included after shoulda-matchers and hence it overrides the method. Two options here - either change the order of inclusion of those two modules (which then will...
ruby-on-rails,testing,mongoid,minitest,shoulda
This is a bug in the latest version of shoulda-matchers. We are working to fix it, but in the meantime, please use version 2.5.0.
ruby-on-rails,rspec,rspec-rails,shoulda
ok, first you have to understand the the validate_presence_of matcher... sets the value of that attribute to nil... and tests that you get an error. Think of what that means for your before-validation. You have nothing in strength... then before you get to the validation the before-validation trigger is triggered......
ruby-on-rails,minitest,shoulda
You can use minitest-reporters for this purpose. This gem provide multiple reporters to see output of your tests. Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new Spec reporter shows the time which each test take to run. It shows the time on console, not as a report....
ruby-on-rails,ruby,ruby-on-rails-3,sqlite3,shoulda
The documentation for that matcher says: This matcher works a bit differently than other matchers. As noted before, it will create an instance of your model if one doesn't already exist. Sometimes this step fails, especially if you have database-level restrictions on any attributes other than the one which is...
Well, it will basically do a described_class.new, so you won't have a completion_date. You can fix it like this: describe StudentPiggyBank do context 'with a completion date' do before { subject.completion_date = 7.days.from_now } it { should validate_numericality_of(:interest_rate).is_greater_than_or_equal_to(0) } end end ...
ruby-on-rails,rspec,capybara,shoulda
The within method is used for scoping where to look for an element. For example, you might want to only look for the radio button in a certain div: within(:css, '#some_parent_div') do find(:css, '#rating_commute_8').should be_checked end In this case, assuming the radio button's id is unique, you do not need...
ruby-on-rails,ruby,ruby-on-rails-4,shoulda
It looks like you don't have a Friend class which the belongs_to is looking for. I suspect that the friend relation is also a supposed to be a User object, in which case you need something like this: class UserFriendship < ActiveRecord::Base belongs_to :user belongs_to :friend, class_name: "User" end ...