无法在 circleci 中 运行 elastic search 使我的 rspec for elasticsearch 通过?
Cannot run elastic search in circleci to make my rspec for elasticsearch to pass?
我已经在 github 中使用 circleci 配置了我的项目。我正在使用 searchkick 进行弹性搜索。
我的重建索引代码如下所示:
IN spec_helper.rb
RSpec.configure do |config|
....
config.before :each do
Location.reindex
end
...
end
我的 app/models/location.rb 看起来像这样
class Location < ActiveRecord::Base
...
searchkick word_start: [:location_name], autocomplete: [:location_name]
...
end
我的 app/models/search.rb 看起来像这样
class Search < ActiveRecord::Base
...
def self.location_auto_complete(search_term)
location_ids = Organization.locations.map(&:id)
Location.search(search_term, fields: [{location_name: :word_start}, :from, :search_id], where: {id: location_ids})
end
end
我的 /spec/models/search_spec.rb 看起来像这样
require 'rails_helper'
describe Search, type: :model do
before :each do
@location = create(:location,location_name: 'kathmandu')
@location.reindex
Location.searchkick_index.refresh
end
describe '.location_auto_complete(search_term)' do
it 'return location search result for the location search term' do
expect(Search.location_auto_complete('kathmandu')).to match_array(@location)
end
结束
我的 /myapp/config/circle.yml 看起来像我遵循的:https://circleci.com/docs/installing-elasticsearch :
database:
override:
# replace CircleCI's generated database.yml
- cp config/database.yml.ci config/database.yml
- bundle exec rake db:drop db:create db:migrate
machine:
services:
- elasticsearch
dependencies:
post:
- wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz
- tar -xvf elasticsearch-1.0.1.tar.gz
- elasticsearch-1.0.1/bin/elasticsearch: {background: true}
dependencies:
cache_directories:
- elasticsearch-1.0.1 # relative to the build directory
post:
- if [[ ! -e elasticsearch-1.0.1 ]]; then wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz && tar -xvf elasticsearch-1.0.1.tar.gz; fi
- elasticsearch-1.0.1/bin/elasticsearch: {background: true}
当我 运行 rspec 在我的笔记本电脑上时,当我推送到 github(与 circleci 集成)时它工作正常,状态为失败。它还说:
We didn't find a circle.yml for this build. You can specify deployment or override our inferred test steps from a circle.yml checked in to your repo's root directory.More information in our docs.
错误消息说 circle.yml
应该在 repo 的根目录中,但你把它放在 config
目录中。
我已经在 github 中使用 circleci 配置了我的项目。我正在使用 searchkick 进行弹性搜索。 我的重建索引代码如下所示:
IN spec_helper.rb
RSpec.configure do |config|
....
config.before :each do
Location.reindex
end
...
end
我的 app/models/location.rb 看起来像这样
class Location < ActiveRecord::Base
...
searchkick word_start: [:location_name], autocomplete: [:location_name]
...
end
我的 app/models/search.rb 看起来像这样
class Search < ActiveRecord::Base
...
def self.location_auto_complete(search_term)
location_ids = Organization.locations.map(&:id)
Location.search(search_term, fields: [{location_name: :word_start}, :from, :search_id], where: {id: location_ids})
end
end
我的 /spec/models/search_spec.rb 看起来像这样
require 'rails_helper'
describe Search, type: :model do
before :each do
@location = create(:location,location_name: 'kathmandu')
@location.reindex
Location.searchkick_index.refresh
end
describe '.location_auto_complete(search_term)' do
it 'return location search result for the location search term' do
expect(Search.location_auto_complete('kathmandu')).to match_array(@location)
end
结束
我的 /myapp/config/circle.yml 看起来像我遵循的:https://circleci.com/docs/installing-elasticsearch :
database:
override:
# replace CircleCI's generated database.yml
- cp config/database.yml.ci config/database.yml
- bundle exec rake db:drop db:create db:migrate
machine:
services:
- elasticsearch
dependencies:
post:
- wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz
- tar -xvf elasticsearch-1.0.1.tar.gz
- elasticsearch-1.0.1/bin/elasticsearch: {background: true}
dependencies:
cache_directories:
- elasticsearch-1.0.1 # relative to the build directory
post:
- if [[ ! -e elasticsearch-1.0.1 ]]; then wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz && tar -xvf elasticsearch-1.0.1.tar.gz; fi
- elasticsearch-1.0.1/bin/elasticsearch: {background: true}
当我 运行 rspec 在我的笔记本电脑上时,当我推送到 github(与 circleci 集成)时它工作正常,状态为失败。它还说:
We didn't find a circle.yml for this build. You can specify deployment or override our inferred test steps from a circle.yml checked in to your repo's root directory.More information in our docs.
错误消息说 circle.yml
应该在 repo 的根目录中,但你把它放在 config
目录中。