Ich verwende die fantastische wisper gem, um auf Änderungen in meinen Modellen (Rails 4.1) zu reagieren.Rails "Test" -Umgebung hat Zugang zu nicht enthaltenen Methoden
Class Transaction < ActiveRecord::Base
#include Wisper::Publisher
after_save { broadcast(:transaction_saved)}
end
Hier broadcast
ein Verfahren, mit dem Wisper::Publisher
Modul, die Einbeziehung von denen auf Kommentar versehen ist, wie Sie oben sehen können.
Durch all dies, verstehe ich nicht, wie ein Test wie dieser, ohne zu klagen über passieren kann „broadcast
Methode fehlt“:
require 'test_helper'
class TransactionTest < ActiveSupport::TestCase
include GeneralHelper # this doesnt include any other module
def setup
@tr = Transaction.create(...)
end
def test_transaction_method
@tr.update_attributes(amount:100)
end
end
Wie erwartet development/production
Umgebungen tun bemängeln Methode fehlt
- Update test/test_helper.rb
ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "mocha/mini_test"
require 'minitest/reporters'
Minitest::Reporters.use!(
Minitest::Reporters::ProgressReporter.new,
ENV,
Minitest.backtrace_filter)
# Capybara and poltergeist integration
require "capybara/rails"
require "capybara/poltergeist"
Capybara.javascript_driver = :poltergeist
class ActiveSupport::TestCase
ActiveRecord::Migration.check_pending!
include FactoryGirl::Syntax::Methods
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
def assert_valid(model, msg = nil)
msg = message(msg) { "Expected #{model} to be valid, but got errors: #{errors}." }
valid = model.valid?
errors = model.errors.full_messages.join(', ')
assert valid, msg
end
end
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.13'
# Use pg as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails'#, '~> 4.0.2'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-turbolinks'
#gem 'bootstrap-sass'
gem 'font-awesome-rails'
gem 'simple-line-icons-rails'
gem 'active_link_to'
gem 'country_select', github: 'stefanpenner/country_select'
gem 'chronic'
gem 'will_paginate'#, '3.0.4'
gem 'will_paginate-bootstrap'
#Editable
#gem 'bootstrap-editable-rails'
#Encryption
gem 'aes'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
gem 'redis'
gem 'firebase'
# Use unicorn as the app server
gem 'puma'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
gem 'recipient_interceptor'
group :test, :development do
#gem 'rspec-rails'
#gem 'rspec-its'
gem 'pry'
gem 'pry-nav'
gem 'pry-rails'
end
gem 'nokogiri'
gem 'faker'
gem 'haml'
gem 'slim'
gem 'rack-mini-profiler'
gem 'newrelic_rpm'
#gem 'appsignal'
group :test do
gem 'capybara'
#gem 'capybara-webkit'
gem 'factory_girl_rails'
#gem "connection_pool"
#gem "launchy"
gem "minitest"
gem "minitest-reporters"
gem "mocha"
gem "poltergeist"
#gem "shoulda"
end
gem 'axlsx'
gem 'prawn'
gem 'active_model_serializers'
gem 'card-rails'
gem 'rails_12factor', group: :production
#gem 'twitter-typeahead-rails', :git => "git://github.com/yourabi/twitter-typeahead-rails.git"
gem 'rack-cors', :require => 'rack/cors'
gem 'sidekiq'
gem 'rest-client'
gem 'nest'
gem 'redic'
gem 'fog'
gem 'aws-sdk'
gem 'twilio-ruby'
gem 'react-rails', '~> 1.0'
gem 'wisper', '2.0.0.rc1'
gem 'ruby-prof'
gem 'le'
gem 'mechanize'
gem 'mandrill-api'
gem 'business_time'
gem 'paleta'
gem "aftership", "~> 4.3.1"
Veröffentlichen Sie Ihre Gemfile. Beitrag test_helper.rb – 7stud
@ 7stud du hast recht, fertig! – lllllll
Es ist hilfreich für zukünftige Leser, eine Antwort zu posten, anstatt die Frage ungelöst zu lassen –