rspec test fails to enable javascript - ruby-on-rails

I have the next test with rspec and selenium:
require 'rails_helper'
feature "Creating an student" do
context "When an student visit the sign_up page" do
scenario "Should be able to create an student" do
state = FactoryGirl.create(:state)
city = FactoryGirl.create(:city, state: state)
institution = FactoryGirl.create(:institution)
visit root_path
.........
The devise function to register is this:
def new
#institutions = Institution.all.order(:name)
#states = State.all
#cities = City.all
super
end
when I search in my controller the States and Cities, I found this, but when I enable javascript
scenario "Should be able to create an student", js: true do
the States and Cities return nil.
Update 1
My spec_helper file is this:
require 'database_cleaner'
require 'capybara'
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.javascript_driver = :chrome
Capybara.default_max_wait_time = 10
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.strategy = :transaction
end⋅
config.before(:each) do
DatabaseCleaner.start
end⋅
config.after(:each) do
DatabaseCleaner.clean
end⋅
end
I do not know why this happens.

Related

Attempted to assign to readonly property on Capybara

I'm working on updating a rails 3.2 app to rails 4.2.10, I've got almost everything worked out, unit tests and integration tests passing.
I'm having some issues with feature tests, I'm using capybara 3.3.0 and poltergeist 1.18.1 and it throws me error on visit '/'
I've looked at lots of issues on Stack regarding Attemped to assign to readonly property but none of them apply to my case here,
This is my stripped down spec file
require 'vcr'
Capybara.default_max_wait_time = 10
feature "Create something" do
include SpecHelpers
include Acceptance
before do
setup_database
end
after do
teardown_database
end
scenario "Creating a Consignment", :js => true do
puts "Running with #{Capybara.current_driver}"
VCR.use_cassette('cassette_name.yml') do
page.driver.resize(1000,2200) unless Capybara.current_driver == :selenium
visit '/'
expect(page).to have_content 'EMAIL'
expect(page).to have_content 'PASSWORD'
end
end
end
This is my stripped down spec helper file
ENV["RAILS_ENV"] ||= 'test'
require_relative '../config/environment.rb'
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/poltergeist'
require 'shoulda/matchers'
require 'redis'
require 'redis-namespace'
require 'resque'
require 'mock_redis'
require 'bcrypt'
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
# rspec
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
RSpec.configure do |config|
config.deprecation_stream = 'log/deprecations.log'
end
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, :type => :controller
end
RSpec::Expectations.configuration.on_potential_false_positives = :nothing
BCrypt::Engine.cost = 1
if (ENV['DEBUG_CAP'])
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
else
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {js_errors: true})
end
Capybara.javascript_driver = :poltergeist
end
Capybara.server_port = 31337
Capybara.server = :webrick
module SpecHelpers
def setup_database
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.start
end
def teardown_database
DatabaseCleaner.clean
end
end
module Acceptance
VCR.configure do |c|
require 'webmock'
c.hook_into :webmock
c.cassette_library_dir = 'fixtures/vcr_cassettes'
c.allow_http_connections_when_no_cassette = true
c.default_cassette_options = {:record => :new_episodes}
c.ignore_request do |request|
URI(request.uri).port == Capybara.server_port || request.uri=~/shutdown/ || request.uri=~/session/
end
end
def wait_until(timeout = Capybara.default_max_wait_time)
require "timeout"
begin
Timeout.timeout(timeout) do
sleep(0.3) until value = yield
value
end
rescue => e
save_screenshot "capybara_#{Time.now.to_i}.png"
puts e.message
puts e.backtrace
raise e
end
end
end
require "rspec/mocks/standalone"
....
This is the error stack trace
Running with poltergeist
Error: Attempted to assign to readonly property.
r#http://127.0.0.1:31337/lib/bfd57c67.components.js:22:3139
r#http://127.0.0.1:31337/lib/bfd57c67.components.js:5:3551
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:19730
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12707
s#http://127.0.0.1:31337/lib/bfd57c67.components.js:4:20964
g#http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12573
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:16265
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:22205
c#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
c#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4884
$digest#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:7801
$apply#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:9410
http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26430
a#http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26340
Z#http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26051
http://127.0.0.1:31337/lib/bfd57c67.components.js:7:28112
d#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:18351
fireWith#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:19152
ready#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:13970
wt#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:11347
Error: Attempted to assign to readonly property.
r#http://127.0.0.1:31337/lib/bfd57c67.components.js:22:3139
r#http://127.0.0.1:31337/lib/bfd57c67.components.js:5:3551
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:19730
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12707
s#http://127.0.0.1:31337/lib/bfd57c67.components.js:4:20964
g#http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12573
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:16265
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:22205
c#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
c#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4884
$digest#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:7801
$apply#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:9410
http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26430
a#http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26340
Z#http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26051
http://127.0.0.1:31337/lib/bfd57c67.components.js:7:28112
d#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:18351
fireWith#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:19152
ready#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:13970
wt#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:11347
Error: Attempted to assign to readonly property.
r#http://127.0.0.1:31337/lib/bfd57c67.components.js:22:3139
r#http://127.0.0.1:31337/lib/bfd57c67.components.js:5:3551
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:19730
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12707
s#http://127.0.0.1:31337/lib/bfd57c67.components.js:4:20964
g#http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12573
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:16265
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:22205
c#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
c#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4884
$digest#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:7801
$apply#http://127.0.0.1:31337/lib/bfd57c67.components.js:6:9410
http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26430
a#http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26340
Z#http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26051
http://127.0.0.1:31337/lib/bfd57c67.components.js:7:28112
d#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:18351
fireWith#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:19152
ready#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:13970
wt#http://127.0.0.1:31337/lib/bfd57c67.components.js:1:11347
Update 1
Upon some debugging, it turns out that error gets thrown from angularjs-bootstrap-datetimepicker package when it tries to set $render to a function,
var ngModelController = $element.controller('ngModel')
var configuration = createConfiguration()
$scope.screenReader = configuration.screenReader
// Behavior
$scope.changeView = changeView
ngModelController.$render = $render --> in this line

Capybara not holding user session after one page visit -- Rails 4.2

I can't get Capybara to hold a session beyond one page visit within one spec. I am familiar with the concept that Capybara's driver might be using a different database connection, but anything I do (including not using :js => true) doesn't seem to change anything.
I am just trying to visit a page that requires user authentication. It succeeds on first visit. It fails when I visit it a second time. (This of course all works when I manually test in development.) Code:
activity_areas_spec.rb
require "rails_helper"
RSpec.feature "Activity areas", :type => :feature do
user = FactoryGirl.create(:user)
before(:each) do
login_as(user, :scope => :user)
end
after(:each) do
Warden.test_reset!
end
...
feature "displays activities shared", :js => true do
scenario "to public" do
visit area_activities_path
expect(page).to have_content I18n.t('pages.activity.areas.title') #passes
visit area_activities_path
expect(page).to have_content I18n.t('pages.activity.areas.title') #fails -- user is redirected to login page.
end
end
end
#rails_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require 'spec_helper'
require 'capybara/rails'
require 'devise'
require 'support/controller_macros'
include Warden::Test::Helpers
Warden.test_mode!
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Factory girl
config.include FactoryGirl::Syntax::Methods
# Make routes available in specs
config.include Rails.application.routes.url_helpers
# Capybara
config.include Capybara::DSL
# To get Devise test helpers
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros::DeviseHelper, :type => :controller
config.include ControllerMacros::AttributeHelper, :type => :controller
config.use_transactional_fixtures = false
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
# Database cleaner gem configurations
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
Since I was sensitive to the fact that Capy might be using a different database connection, I have tried following DatabaseCleaner's suggested code to the tee in the place of the above DatabaseCleaner commands:
config.before(:suite) do
if config.use_transactional_fixtures?
raise(<<-MSG)
Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
(or set it to false) to prevent uncommitted transactions being used in
JavaScript-dependent specs.
During testing, the app-under-test that the browser driver connects to
uses a different database connection to the database connection used by
the spec. The app's database connection would not be able to access
uncommitted transaction data setup over the spec's database connection.
MSG
end
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, type: :feature) do
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
if !driver_shares_db_connection_with_specs
DatabaseCleaner.strategy = :truncation
end
end
config.before(:each) do
DatabaseCleaner.start
end
config.append_after(:each) do
DatabaseCleaner.clean
end
See here.
#spec_helper.rb
require 'factory_girl_rails'
require "capybara/rspec"
require 'sidekiq/testing'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
end
I'm confused easily, so much appreciated for any help that is provided in simple terms. And let me know if you need any other files.
As a quick guess your user = FactoryGirl.create(:user) needs to be inside your before block - otherwise it would only be run once when the feature is loaded - and then removed from the database before the first feature is run

RSpec + DatabaseCleaner + PhantomJS: database get randomly erased during example with js

I have a simple scenario in my rspec feature:
require 'spec_helper'
feature 'CLIENT views results page' do
context 'from welcome/index form' do
let!(:location) { FactoryGirl.create :location, name: 'town' }
before :each do
visit '/'
end
scenario 'successfully', js: true do
expect(Location.count).to eq 1
fill_in 'from_address', with: 'Some address'
fill_in 'to_address', with: 'Another address'
click_button 'Search'
expect(page).to have_content 'Some address → Another address'
end
end
end
spec_helper:
require 'rubygems'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'factory_girl'
require 'database_cleaner'
require 'capybara/poltergeist'
FactoryGirl.reload
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.infer_base_class_for_anonymous_controllers = true
config.order = "random"
config.tty = true
config.mock_with :rspec
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.treat_symbols_as_metadata_keys_with_true_values = true
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
Capybara.javascript_driver = :poltergeist
Capybara.asset_host = "http://localhost:3000"
Capybara.server_port = 9887 + ENV['TEST_ENV_NUMBER'].to_i
And my scenario fails on some random step (after expect(Location.count).to eq 1) due to the fact, that there are no Location records:
(byebug) Location.all
[]
I think it might be one of two cases:
Either DatabaseCleaner cleans database before an example finishes
Or there are actually two threads with two databases, one of which (the one that is used by the app) is really empty
Gem versions:
rspec (2.14.1)
rspec-core (2.14.8)
rspec-rails (2.14.0)
phantomjs (1.9.7.1)
rails (3.2.21)
database_cleaner (0.9.1)
I remember having issues with this as well. My config for DB cleaning looks like this:
config.before(:each) do
if Capybara.current_driver == :rack_test
DatabaseCleaner.strategy = :transaction
else
DatabaseCleaner.strategy = :truncation
end
DatabaseCleaner.start
end
config.after do
DatabaseCleaner.clean
end
Maybe it has something to do with the order your before blocks are called. So if DatabaseCleaner.start is called before you wanted strategy is set, you might see such results.
Managed to solve this issue by migrating to
config.use_transactional_fixtures = true
instead of using DatabaseCleaner. Some workarounds are suggested to make transactional cleaning work with javascript tests. I chose this one:
(adding somewhere in the beginning of spec/spec_helper)
class ActiveRecord::Base
mattr_accessor :shared_connection
##shared_connection = nil
def self.connection
##shared_connection || retrieve_connection
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
cause it seemed to work faster, still leaving some spontaneously failing tests (might not be the problem related to database).

Rails: Can not save on DB during rspec features test

I'm using rspec to perform feature tests and I can't save the user in the DB before the log in.
I'm using factory girl to build the object.
fixture are saved in db at the beginning of the test but are not deleted at the end.(maybe because the test fail. I don't know)
So I can not save the user before clicking on logIn and I get this errror message
--
DEPRECATION WARNING: an empty resource was given to Devise::Strategies::DatabaseAuthenticatable#validate. Please ensure the resource is not nil. (called from set_required_vars at app/controllers/application_controller.rb:43)
spec/features/login_to_mainpage_spec.rb (no error are rescued)
require "rails_helper"
feature 'Navigating to homepage' do
let(:user) { create(:user) }
let(:login_page) { MainLoginPage.new }
scenario "login" do
login_page.visit_page.login(user)
sleep(20)
end
end
A simple page object: spec/features/pages_objects/main_login_page.rb
class MainLoginPage
include Capybara::DSL
def login(user)
fill_in 'email', with: user.email
fill_in 'password', with: "password"
click_on 'logIn'
end
def visit_page
visit '/'
self
end
end
my rails_helper
require 'spec_helper'
require 'capybara/rspec'
require 'capybara/poltergeist'
require "selenium-webdriver"
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Dir[Rails.root.join("spec/features/page_objects/**/*.rb")].each { |f| require f }
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = false
config.before :each do
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
config.infer_spec_type_from_file_location!
config.include Devise::TestHelpers, :type => :controller
end
Capybara.default_driver = :selenium
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :firefox)
end
in spec helper:
require 'simplecov'
require 'factory_girl'
require 'rspec/autorun'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
ENV["RAILS_ENV"] ||= 'test'
RSpec.configure do |config|
include ActionDispatch::TestProcess
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.disable_monkey_patching!
if config.files_to_run.one?
config.default_formatter = 'doc'
end
config.profile_examples = 10
config.order = :random
Kernel.srand config.seed
end
EDIT 1
I switch "gem 'factory_girl'" to "gem 'factory_girl_rails'"
and add this to application.rb
config.generators do
|g|
g.test_framework :rspec,
:fixtures => true,
:view_specs => false,
:helper_specs => false,
:routing_specs => false,
:controller_specs => true,
:request_specs => true
g.fixture_replacement :factory_girl, :dir => "spec/factories"
end
I still can not save the user in DB.
Everything pass but I put some sleep(10) in by code to refresh my DB and see te records and user is never saved
EDIT 3
My problem is actually very simple. FactoryGirl.create never save the data in DB if I put in my rails_helper:
config.use_transactional_fixtures = true
or
config.before :each do
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
/spec/factories
FactoryGirl.define do
factory :user do
email 'pierre#tralala.com'
password 'password'
password_confirmation 'password'
end
/spec/support/factory_girl.rb
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
spec/features/login_to_mainpage_spec.rb
let(:user) { create(:user) }
scenario "login" do
login_page.visit_page.login(create(:user))
sleep(5)
end
User will not be saved because of the config I cited before.
I need to have data reseted between tests.
EDIT 4
If I'm using the console
RAILS_ENV=test rails c
FactoryGirl.create(:user) it is saved in db.
I don't understand why it does not work in my tests.
Try using let! to create your user.
From the rSpec documentation:
Note that let is lazy-evaluated: it is not evaluated until the first time
the method it defines is invoked. You can use let! to force the method's
invocation before each example.
You said that you are using FactoryGirl but I do not see this in your test. To create my Users with FactoryGirl I always do something like this:
FactoryGirl.create(:user, password: 'test', password_confirmation: 'test', name: 'test')
If setup correctly in your Factory you can just write:
FactoryGirl.create(:user)
To solve your problem with the unique fields FactoryGirl provides you sequences:
sequence :email do |n|
"person#{n}#example.com"
end
factory :user do
email { generate(:email }
end
This will start with "person1#example.com" and add 1 to the number each time FactoryGirl.create(:user) is called.

Object is created. (RoR, Database Cleaner, Factory Girl)

I'm a beginner in Rails, help me, I do not understand what the problem is. It seems like something else is written before(:each)...
And How can I write a test in test_spac.rb in which no Card object is created. That the method before(:each) did not work for this test.
This is work:
test_spec.rb:
require 'rails_helper'
describe "Index Page" do
before(:each) do
#card = FactoryGirl.create(:card)
DatabaseCleaner.start
end
it "shows error messages if translation is wrong" do
visit root_path
fill_in 'translated_text', with: 'wqww'
click_on 'Проверить'
expect(page).to have_content('Неверно!')
end
after(:each) do
DatabaseCleaner.clean
end
end
rails_helper.rb:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/poltergeist'
require 'database_cleaner'
Capybara.javascript_driver = :poltergeist
Capybara.default_driver = :poltergeist
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = false
config.before(:each) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each, type: :features) do
DatabaseCleaner.strategy = :truncation
end
config.infer_spec_type_from_file_location!
end
This is NOT Work:
test_spec.rb:
require 'rails_helper'
describe "Index Page" do
before(:each) do
#card = FactoryGirl.create(:card)
end
it "shows error messages if translation is wrong" do
visit root_path
fill_in 'translated_text', with: 'wqww'
click_on 'Проверить'
expect(page).to have_content('Неверно!')
end
end
rails_helper.rb:
config.use_transactional_fixtures = false
config.before(:each) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each, type: :features) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
Problem solved:
I make this: (test_spec.rb)
require 'rails_helper'
describe "Index Page" do
it "check behavior then translation is wrong" do
FactoryGirl.create(:card) #################
visit root_path
fill_in 'translated_text', with: 'some text'
click_on 'Проверить'
expect(page).to have_content('Неверно!')
end
it "check page then object is not created" do
visit root_path
expect(page).to have_content('Непросмотренных')
end
end
Could you post what you mean by not working? Are you getting any error messages?
By the way, why do you have config.use_transactional_fixtures disabled? If you stick to using before(:each) hooks, RSpec will reset the database for you and you shouldn't need to use the DatabaseCleaner.

Resources