I am setting up a project and have been trying to make rr mocks work but I am getting nomethod error. I have tried moving the required method as well but nothing works. This is my repo
$ rspec spec/views
F
Failures:
1) home/show.html.haml
Failure/Error: stub(view).user { user }
NoMethodError:
undefined method `stub' for #<RSpec::ExampleGroups::HomeShowHtmlHaml:0x007fc245188f08>
# ./spec/views/home/show.html.haml_spec.rb:6:in `block (2 levels) in <top (required)>'
# /Users/saadbinakhlaq/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `load'
# /Users/saadbinakhlaq/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
# /Users/saadbinakhlaq/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:24:in `run'
# /Users/saadbinakhlaq/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:304:in `exec'
# /Users/saadbinakhlaq/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'
# /Users/saadbinakhlaq/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/exe/bundle:27:in `block in <top (required)>'
# /Users/saadbinakhlaq/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
# /Users/saadbinakhlaq/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'
I have tried whatever was mentioned here rr
# Gemfile
group :test do
gem 'rr', require: false
end
# test helper
require File.expand_path('../../config/environment', __FILE__)
require 'your/test/framework' # if you are using something other than MiniTest / Test::Unit
require 'rr'
I got this working finally, I used gem 'rr', '1.1.2' instead of 1.2.0 which got auto installed when running bundler without the gem version.
Related
I am building a Ruby project that uses active record but not rails. Inside one of my tests I am trying the following:
it "fails with no driver name" do
command = "Driver"
expect {command_file.process_driver command}.to raise_error(ActiveRecord::RecordInvalid)
end
And here is the method I am trying to call
def process_driver command
driver_name = command.split[1]
Driver.create! :name => driver_name
end
I expect to be passing :name => nil to Driver.create! which should throw a RecordInvalid but instead I get I18n::InvalidLocaleData. Here is the backtrace
expected ActiveRecord::RecordInvalid, got #<I18n::InvalidLocaleData: can not load translations from /Users/me/.rbenv/versions/2.3.1/lib/r...ems/activesupport-5.1.3/lib/active_support/locale/en.yml: expects it to return a hash, but does not> with backtrace:
# ./command_file.rb:81:in `process_driver'
# ./command_file.rb:63:in `block in process'
# ./command_file.rb:51:in `each'
# ./command_file.rb:51:in `each_with_index'
# ./command_file.rb:51:in `process'
# ./spec/command_file_spec.rb:60:in `block (5 levels) in <top (required)>'
# ./spec/command_file_spec.rb:60:in `block (4 levels) in <top (required)>'
# ./spec/spec_helper.rb:75:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:74:in `block (2 levels) in <top (required)>'
And here is my Gemfile
source 'https://rubygems.org'
gem 'sqlite3', '~> 1.3', '>= 1.3.13'
gem 'activerecord', '~> 5.1', '>= 5.1.3'
gem 'pry', '~> 0.10.4'
gem 'rspec', '~> 3.6'
gem 'factory_girl', '~> 4.5'
group :test do
gem 'database_cleaner'
end
I have no locale files of my own.
Any idea what's going on? I am not attempting any kind of translation in this project. I also don't understand why a locale file provided by active_support should fail. I'd be happy to simply disable i18n somehow if that were possible but I don't know how. Any ideas what the problem is?
For what ever reason :en was not set as my default locale. I fixed that in my spec_helper.rb by adding I18n.default_locale = 'en':
I18n.default_locale = 'en' # <--- add this line
RSpec.configure do |config|
# config here...
end
I realize this doesn't fix the larger problem of why the locale file from active_support was not loading, but my challenge was simply to make the error go away, not to use i18n
My Ruby file
require 'puppet'
# ...
require 'googleauth'
module PuppetX
module Puppetlabs
module Google_cloud_dns
class Provider < PuppetX::Puppetlabs::Swagger::Provider
def client
self.class.client
end
My RSpec file
I am using this two alternatively, but none of them working:
require_relative'../../lib/puppet_x/puppetlabs/google_cloud_dns/provider'
File.expand_path("../../lib/puppet_x/puppetlabs/google_cloud_dns/provider.rb",File.dirname(__FILE__)))
require 'spec_helper'
require_relative '../../lib/puppet_x/puppetlabs/google_cloud_dns/provider'
File.expand_path("../../lib/puppet_x/puppetlabs/google_cloud_dns/provider.rb", File.dirname(__FILE__))
describe Provider do
it "checks function" do
provide = Provider.new
provide.should respond_to :client
end
end
The error which I am getting
rspec Mymodule/gc_dns/puppet-google_cloud_dns/spec/classes/provider_spec.rb --format documentation/home/vivekkumarmishra17/Mymodule/gc_dns/puppet-google_cloud_dns/spec/classes/provider_spec.rb:19:in `<top (required)>': uninitialized constant Provider (NameError)
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `load'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `each'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in `setup'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
from /usr/local/bin/rspec:23:in `load'
from /usr/local/bin/rspec:23:in `<main>'
Can anyone tell what I am doing wrong?
I am trying to get cucumber working on my Mac for testing a ruby script. I use cucumber with rails and have never had an issue setting it up there, but seem to be having quite an issue creating it just for a ruby script that I want to test.
Script background: I have created a script that serves mysql data via a TCPServer connection and I want to be able to test this functionality. So ideally I launch the script so that it accepts incoming connections and depending on what I am attempting to get to it presents an error or the data end point.
Here is what I have and the error is below the settings:
features/support/env.rb
require_relative File.expand_path('../../../lib/requirements',FILE)
require "capybara/cucumber"
require 'capybara/dsl'
require "rspec"
# Capybara.default_driver = :selenium
Capybara.app_host = 'http://localhost:7125'
World(Capybara.app = "Api")
World(Capybara::DSL)
World(RSpec::Matchers)
features/rmws.feature
Feature: Test conversion of mysql output to JSON
Scenario:
Given the index page can be reached
And There is MYSQL data
When converted to hash
And and /mysql location is hit
Then the data is show in JSON
features/step_definitions/rwms_step_definitions.rb
Given(/^the index page can be reached$/) do
visit 'http://localhost:7125'
expect(page).to have_content 'This is the index page'
end
Given(/^There is MYSQL data$/) do
pending # express the regexp above with the code you wish you had
end
When(/^converted to hash$/) do
pending # express the regexp above with the code you wish you had
end
When(/^and \/mysql location is hit$/) do
pending # express the regexp above with the code you wish you had
end
Then(/^the data is show in JSON$/) do
pending # express the regexp above with the code you wish you had
end
Output
$ cucumber
Feature: Test conversion of mysql output to JSON
Scenario: # features/rmws.feature:3
wrong argument type String (expected Module) (TypeError)
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:150:in `extend'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:150:in `block in extend_world'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:149:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:149:in `extend_world'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:94:in `begin_rb_scenario'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:128:in `begin_scenario'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:14:in `before'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:112:in `block in fire_hook'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:111:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:111:in `fire_hook'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:107:in `before'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:98:in `before_and_after'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:82:in `block in with_hooks'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:120:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:120:in `block (3 levels) in around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:9:in `block in around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:97:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:97:in `execute_around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:8:in `around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:119:in `block (2 levels) in around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:123:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:123:in `around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:94:in `around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:81:in `with_hooks'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:13:in `execute'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/scenario.rb:32:in `block in accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/scenario.rb:79:in `with_visitor'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/scenario.rb:31:in `accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:58:in `block in visit_feature_element'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:57:in `visit_feature_element'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/feature.rb:38:in `block in accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/feature.rb:37:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/feature.rb:37:in `accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:27:in `block in visit_feature'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:26:in `visit_feature'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:28:in `block in accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:17:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:17:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:27:in `accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:21:in `block in visit_features'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:20:in `visit_features'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:49:in `run!'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/cli/main.rb:47:in `execute!'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/bin/cucumber:13:in `<top (required)>'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/cucumber:23:in `load'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/cucumber:23:in `<main>'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `eval'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `<main>'
$
You could use rake to run cucumber tests, I use it for a gem that I wrote. You can find additional doc here
require 'bundler'
require 'rake/clean'
require 'rake/testtask'
require 'cucumber'
require 'cucumber/rake/task'
require 'rspec/core/rake_task'
Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
t.fork = false
end
Run cucumber --init to get the testing suite set up.
I want to extend the faker gem for rails to also generate other random date (in my case computer game names)
#lib/extended_faker.rb
require 'faker'
require 'extended_faker/game'
#lib/extended_faker/game.rb
Module Faker
class Game < Faker::Base
class << self
def name
fetch('game.name')
end
end
end
end
#config/locals/faker_en.yml
en:
faker:
game:
name: ["a", "b", "c"]
#config/application.rb
...
config.autoload_paths += Dir["#{config.root}/lib/**/"]
...
then when i run it in a rails console i get the following
Loading development environment (Rails 3.2.9)
1.9.3p194 :001 > Faker::Game.name
LoadError: Expected /home/enermis/School/Projects/IG/test/lib/extended_faker/game.rb to define Game
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:503:in `load_missing_constant'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `each'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `const_missing'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:514:in `load_missing_constant'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `each'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `const_missing'
from (irb):1
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.9/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
When i change the lib/extended_faker/game.rb file to this
require 'faker'
require 'extended_faker/game'
include 'extended_faker/item'
include 'extended_faker/team'
i get weird behavior in the console
Loading development environment (Rails 3.2.9)
1.9.3p194 :001 > Faker::Game.name
=> "b"
1.9.3p194 :002 > Faker::Game.name
NameError: uninitialized constant Faker::Game
from (irb):2
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
from /home/enermis/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.9/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
The weird thing i don't understand is that the first time i run the generator, i get a valid result, but the second time around i get an error...
What am i missing?
you shoud put it in
lib/faker/game.rb
starting in the lib directory, rails convention is outermost module name -> in are folder names. Then the actual class/module name is the file name, underscored to the camelcase.
Another example
module Foo
module Bar
class BazParty
def self.hello
puts "hello"
end
end
end
end
would go in lib/foo/bar/baz_party.rb
So this is kind of baffling me as I can't quite figure out why it's happening. This only happens on my laptop (Ubuntu 11.04), and not elsewhere. I just seem to have something weird with the setup on this one computer.
I keep getting the following error when I run my specs:
be rake spec
Gives me:
NoMethodError: undefined method `belong_to' for #<RSpec::Core::ExampleGroup::Nested_4:0xb4eb2e4>
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-expectations-2.6.0/lib/rspec/matchers/method_missing.rb:9:in `method_missing'
/home/tom/work/ruby/litdistco-sales/spec/models/sales_item_spec.rb:5:in `block (2 levels) in <top (required)>'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `instance_eval'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `block in run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:107:in `with_around_hooks'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:45:in `run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:294:in `block in run_examples'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:290:in `map'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:290:in `run_examples'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:262:in `run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `block (2 levels) in run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `map'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `block in run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/reporter.rb:12:in `report'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:21:in `run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80:in `run_in_process'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:69:in `run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:11:in `block in autorun'
Here are the relevant lines from my spec file that generates the complaint:
describe SalesItem do
it { should belong_to(:publisher) }
it { should belong_to(:invoice) }
I'm running Rails 3.1.0. Here is ruby -v:
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
Any tips /thoughts/ideas recommendations greatly appreciated.
Try adding this in your rails_helper.rb
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
RSpec core does not have such matcher. It looks like shoulda-matchers. Just make sure that it's installed and loaded in your spec_helper
I was having a hard time with this for awhile and then changed my spec from:
describe ModelName do
it { should belong_to(:model)}
end
to:
RSpec.describe ModelName, type: :model do
it { should belong_to(:model)}
end
and it suddenly worked
You can write specs like this
describe SalesItem do
describe "Associations" do
it "belongs_to publisher" do
assc = described_class.reflect_on_association(:publisher)
expect(assc.macro).to eq :belongs_to
end
end
end