repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/validator_spec.rb | spec/units/validator_spec.rb | require 'spec_helper'
class NotNilInteractor
include Interactor
include Pulsar::Validator
validate_context_for! :not_nil_property
end
RSpec.describe Pulsar::Validator do
let(:described_instance) { NotNilInteractor.new }
it { expect(described_instance).to respond_to :validate_context! }
describe '#validate_context!' do
subject { NotNilInteractor.call initial_context }
context 'with valid property name' do
let(:initial_context) { { not_nil_property: true } }
it { is_expected.to be_a_success }
it { is_expected.to eql Interactor::Context.new(not_nil_property: true) }
end
context 'with invalid property name' do
let(:initial_context) { { not_nil_property: nil } }
it { is_expected.to be_a_failure }
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/constants_spec.rb | spec/units/constants_spec.rb | require 'spec_helper'
RSpec.describe 'Pulsar Constants' do
context Pulsar::PULSAR_HOME do
subject { Pulsar::PULSAR_HOME }
it { is_expected.to eql File.expand_path('~/.pulsar') }
end
context Pulsar::PULSAR_TMP do
subject { Pulsar::PULSAR_TMP }
it { is_expected.to eql "#{Pulsar::PULSAR_HOME}/tmp" }
end
context Pulsar::PULSAR_CONF do
subject { Pulsar::PULSAR_CONF }
it { is_expected.to eql "#{Pulsar::PULSAR_HOME}/config" }
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/create_run_dirs_spec.rb | spec/units/interactors/create_run_dirs_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CreateRunDirs do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.success' do
around do |example|
Timecop.freeze { example.run }
end
context 'uses a timestamp' do
subject { described_class.call.timestamp }
it { is_expected.to eql Time.now.to_f }
end
context 'creates some folders' do
subject { File }
let(:command) { described_class.call }
it { is_expected.to be_directory("#{Pulsar::PULSAR_HOME}/bundle") }
it { is_expected.to be_directory(command.bundle_path) }
it { is_expected.to be_directory(command.run_path) }
it { is_expected.to be_directory(command.config_path) }
it { is_expected.to be_directory(command.cap_path) }
end
end
describe '.rollback' do
subject { FileUtils }
let(:run_path) { '~/.pulsar/tmp/run' }
before do
allow(subject).to receive(:rm_rf)
allow_any_instance_of(Interactor::Context)
.to receive(:run_path).and_return(run_path)
described_class.new.rollback
end
it { is_expected.to have_received(:rm_rf).with(run_path) }
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/run_capistrano_spec.rb | spec/units/interactors/run_capistrano_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::RunCapistrano do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.success' do
subject { described_class.new context_params }
let(:context_params) do
{
cap_path: RSpec.configuration.pulsar_conf_path, config_path: './config-path',
bundle_path: './bundle-path', environment: 'production',
task: task
}
end
let(:bundle_cmd) do
"BUNDLE_GEMFILE=./config-path/Gemfile BUNDLE_PATH=./bundle-path bundle exec"
end
context 'for plain old deploy command' do
let(:cap_cmd) { "cap production deploy" }
let(:task) { 'deploy' }
before do
allow(Rake).to receive(:sh).and_return(true)
subject.run
end
it { expect(Rake).to have_received(:sh).with("#{bundle_cmd} #{cap_cmd}") }
end
context 'for other capistrano tasks' do
context 'without Capistrano arguments' do
let(:cap_cmd) { "cap production deploy:check" }
let(:task) { 'deploy:check' }
before do
allow(Rake).to receive(:sh).and_return(true)
subject.run
end
it { expect(Rake).to have_received(:sh).with("#{bundle_cmd} #{cap_cmd}") }
end
context 'with Capistrano arguments' do
let(:cap_cmd) { "cap production deploy:check[param1,param2]" }
let(:task) { 'deploy:check[param1,param2]' }
before do
allow(Rake).to receive(:sh).and_return(true)
subject.run
end
it { expect(Rake).to have_received(:sh).with("#{bundle_cmd} #{cap_cmd}") }
end
end
end
context 'failure' do
context 'when no context is passed' do
subject { described_class.call }
it { is_expected.to be_a_failure }
end
context 'when no cap_path context is passed' do
subject do
described_class.call(
config_path: './config-path', bundle_path: './bundle-path',
environment: 'production', task: 'deploy:check'
)
end
it { is_expected.to be_a_failure }
end
context 'when no environment context is passed' do
subject do
described_class.call(
cap_path: './cap-path', config_path: './config-path',
bundle_path: './bundle-path', task: 'deploy:check'
)
end
it { is_expected.to be_a_failure }
end
context 'when no bundle_path context is passed' do
subject do
described_class.call(
cap_path: './cap-path', config_path: './config-path',
environment: 'production', task: 'deploy:check'
)
end
it { is_expected.to be_a_failure }
end
context 'when no config_path context is passed' do
subject do
described_class.call(
cap_path: './cap-path', environment: 'production',
bundle_path: './bundle-path', task: 'deploy:check'
)
end
it { is_expected.to be_a_failure }
end
context 'when no task is passed' do
subject do
described_class.call(
cap_path: './cap-path', config_path: './config-path',
bundle_path: './bundle-path', environment: 'production'
)
end
it { is_expected.to be_a_failure }
end
context 'when the task does not exist' do
subject do
described_class.call(
cap_path: './cap-path', config_path: './config-path',
bundle_path: './bundle-path', environment: 'production',
task: 'unexistent:task'
)
end
it { is_expected.to be_a_failure }
end
context 'when the task is malformed' do
subject do
described_class.call(
cap_path: './cap-path', config_path: './config-path',
bundle_path: './bundle-path', environment: 'production',
task: 'unexistent:task[param1,pa'
)
end
it { is_expected.to be_a_failure }
end
context 'when an exception is triggered' do
subject do
described_class.call(
cap_path: './cap-path', config_path: './config-path',
bundle_path: './bundle-path', environment: 'production',
task: 'deploy:check'
)
end
before { allow(Dir).to receive(:chdir).and_raise(RuntimeError) }
it { is_expected.to be_a_failure }
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/clone_initial_repository_spec.rb | spec/units/interactors/clone_initial_repository_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CopyInitialRepository do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.call' do
subject { described_class.call(directory: './pulsar-conf') }
let(:initial_repo) { './../../../lib/pulsar/generators/initial_repo/' }
context 'success' do
before { allow(FileUtils).to receive(:cp_r) }
it { is_expected.to be_a_success }
it 'copies a template directory to destination' do
subject
expect(FileUtils)
.to have_received(:cp_r)
.with(File.expand_path(initial_repo), subject.directory)
end
end
context 'failure' do
context 'when no directory context is passed' do
subject { described_class.call }
it { is_expected.to be_a_failure }
end
context 'when an exception is triggered' do
before { allow(FileUtils).to receive(:cp_r).and_raise(RuntimeError) }
it { is_expected.to be_a_failure }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/identify_repository_location_spec.rb | spec/units/interactors/identify_repository_location_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::IdentifyRepositoryLocation do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.call' do
subject { described_class.call(repository: repo) }
let(:repo) { './my-conf' }
context 'success' do
before { allow(File).to receive(:exist?) }
it { is_expected.to be_a_success }
context 'when the repository' do
subject { described_class.call(repository: repo).repository_location }
context 'is a local folder' do
before { allow(File).to receive(:exist?).and_return(true) }
it { is_expected.to eql :local }
end
context 'is a local git repository' do
before { allow(File).to receive(:exist?).and_return(false) }
it { is_expected.to eql :remote }
end
end
end
context 'failure' do
context 'when no repository context is passed' do
subject { described_class.call }
it { is_expected.to be_a_failure }
end
context 'when an exception is triggered' do
before { allow(File).to receive(:exist?).and_raise(RuntimeError) }
it { is_expected.to be_a_failure }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/add_applications_spec.rb | spec/units/interactors/add_applications_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::AddApplications do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.call' do
subject { described_class.call(config_path: './my-conf') }
before do
allow(Dir).to receive(:[])
.and_return(%w(./blog/), %w(Capfile deploy.rb production.rb staging.rb))
end
context 'success' do
it { is_expected.to be_a_success }
context 'returns a list of applications and stages' do
subject { described_class.call(config_path: './my-conf').applications }
it { is_expected.to eql('blog' => %w(production staging)) }
end
end
context 'failure' do
context 'when no config_path context is passed' do
subject { described_class.call }
it { is_expected.to be_a_failure }
end
context 'when an exception is triggered' do
before { allow(Dir).to receive(:[]).and_raise(RuntimeError) }
it { is_expected.to be_a_failure }
end
context 'when there are no applications' do
before { allow(Dir).to receive(:[]).and_return([]) }
it { is_expected.to be_a_failure }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/copy_environment_file_spec.rb | spec/units/interactors/copy_environment_file_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CopyEnvironmentFile do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.call' do
subject { command }
let(:command) { described_class.call(args) }
let(:cap_path) { "#{Pulsar::PULSAR_TMP}/cap-path" }
let(:args) do
{
config_path: RSpec.configuration.pulsar_conf_path,
cap_path: cap_path,
applications: { 'blog' => %w(production staging) },
application: 'blog',
environment: 'production'
}
end
context 'success' do
it { is_expected.to be_a_success }
context 'creates a Capfile' do
subject { File }
it { is_expected.to exist(command.environment_file_path) }
context 'with the required Capistrano path' do
subject { command.environment_file_path }
it { is_expected.to eql "#{cap_path}/config/deploy/production.rb" }
end
context 'with contents combined from pulsar configuration repo' do
subject { File.read(command.environment_file_path) }
it { is_expected.to match(/# Production config/) }
end
end
end
context 'failure' do
context 'when no config_path context is passed' do
subject { described_class.call }
it { is_expected.to be_a_failure }
end
context 'when no application context is passed' do
subject { described_class.call(config_path: './my-conf') }
it { is_expected.to be_a_failure }
end
context 'when no cap_path context is passed' do
subject do
described_class.call(config_path: './my-conf', application: 'blog')
end
it { is_expected.to be_a_failure }
end
context 'when no environment context is passed' do
subject do
described_class.call(
cap_path: './some-path', config_path: './my-conf', application: 'blog'
)
end
it { is_expected.to be_a_failure }
end
context 'when an exception is triggered' do
before { allow(FileUtils).to receive(:mkdir_p).and_raise(RuntimeError) }
it { is_expected.to be_a_failure }
end
context 'when passing a missing environment' do
let(:args) do
{
config_path: RSpec.configuration.pulsar_conf_path,
cap_path: cap_path,
applications: { 'blog' => %w(production development) },
application: 'blog',
environment: 'staging'
}
end
it { is_expected.to be_a_failure }
context 'shows a proper error message' do
subject { command.error }
let(:error) do
'The application blog does not have an environment called staging'
end
it { is_expected.to be_an_instance_of Pulsar::ContextError }
it { expect(subject.message).to eql error }
end
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/clone_repository_spec.rb | spec/units/interactors/clone_repository_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CloneRepository do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.call' do
subject do
described_class.call(
config_path: run_path,
repository: repo,
repository_type: type
)
end
let(:repo) { './my-conf' }
let(:run_path) { "#{Pulsar::PULSAR_TMP}/run-#{Time.now.to_f}/conf" }
context 'success' do
context 'when repository_type is :folder' do
let(:type) { :folder }
let(:repo) { RSpec.configuration.pulsar_conf_path }
before do
expect(FileUtils).to receive(:cp_r).with("#{repo}/.", run_path).ordered
end
it { is_expected.to be_a_success }
context 'returns a config_path path' do
subject do
described_class
.call(config_path: run_path, repository: repo, repository_type: type)
.config_path
end
it { is_expected.to match run_path }
end
end
context 'when repository_type is a :git' do
let(:type) { :git }
before do
expect(Rake).to receive(:sh)
.with(/git clone --quiet --depth 1 #{repo} #{run_path}/).ordered
end
it { is_expected.to be_a_success }
context 'returns a config_path path' do
subject do
described_class
.call(config_path: run_path, repository: repo, repository_type: type)
.config_path
end
it { is_expected.to match run_path }
end
end
context 'when repository_type is a :github' do
let(:type) { :github }
let(:repo) { 'github-account/my-conf' }
let(:github_regex) do
/git clone --quiet --depth 1 git@github.com:#{repo}.git #{run_path}/
end
before do
expect(Rake).to receive(:sh).with(github_regex).ordered
end
it { is_expected.to be_a_success }
context 'returns a config_path path' do
subject do
described_class
.call(config_path: run_path, repository: repo, repository_type: type)
.config_path
end
it { is_expected.to match run_path }
end
end
end
context 'failure' do
context 'when no config_path context is passed' do
subject do
described_class.call(repository: './some-path', repository_type: :something)
end
it { is_expected.to be_a_failure }
end
context 'when no repository context is passed' do
subject do
described_class.call(config_path: './some-path', repository_type: :something)
end
it { is_expected.to be_a_failure }
end
context 'when no repository_type context is passed' do
subject do
described_class.call(config_path: './some-path', repository: './some-path')
end
it { is_expected.to be_a_failure }
end
context 'when an exception is triggered' do
let(:type) { :folder }
before { allow(FileUtils).to receive(:cp_r).and_raise(RuntimeError) }
it { is_expected.to be_a_failure }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/create_deploy_file_spec.rb | spec/units/interactors/create_deploy_file_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CreateDeployFile do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.call' do
subject { command }
let(:command) { described_class.call(args) }
let(:cap_path) { "#{Pulsar::PULSAR_TMP}/cap-path" }
let(:args) do
{
config_path: RSpec.configuration.pulsar_conf_path,
cap_path: cap_path, application: 'blog'
}
end
context 'success' do
it { is_expected.to be_a_success }
context 'creates a Capfile' do
subject { File }
it { is_expected.to exist(command.deploy_file_path) }
context 'with the required Capistrano path' do
subject { command.deploy_file_path }
it { is_expected.to eql "#{cap_path}/config/deploy.rb" }
end
context 'with contents combined from pulsar configuration repo' do
subject { File.read(command.deploy_file_path) }
it { is_expected.to match(/# Defaults deployrb\n# App Defaults deployrb/) }
end
end
end
context 'failure' do
context 'when no config_path context is passed' do
subject { described_class.call }
it { is_expected.to be_a_failure }
end
context 'when no application context is passed' do
subject { described_class.call(config_path: './my-conf') }
it { is_expected.to be_a_failure }
end
context 'when no cap_path context is passed' do
subject do
described_class.call(config_path: './my-conf', application: 'blog')
end
it { is_expected.to be_a_failure }
end
context 'when an exception is triggered' do
before { allow(FileUtils).to receive(:touch).and_raise(RuntimeError) }
it { is_expected.to be_a_failure }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/create_capfile_spec.rb | spec/units/interactors/create_capfile_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CreateCapfile do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.call' do
subject { command }
let(:command) { described_class.call(args) }
let(:cap_path) { "#{Pulsar::PULSAR_TMP}/cap-path" }
let(:args) do
{
config_path: RSpec.configuration.pulsar_conf_path,
cap_path: cap_path, application: 'blog', applications: { 'blog' => %w(staging) }
}
end
before { FileUtils.mkdir_p(cap_path) }
context 'success' do
it { is_expected.to be_a_success }
context 'creates a Capfile' do
subject { File }
it { is_expected.to exist(command.capfile_path) }
context 'with the required Capistrano path' do
subject { command.capfile_path }
it { is_expected.to eql "#{cap_path}/Capfile" }
end
context 'with contents combined from pulsar configuration repo' do
subject { File.read(command.capfile_path) }
let(:load_recipes) do
"Dir.glob(\"#{RSpec.configuration.pulsar_conf_path}/recipes/**/*.rake\").each { |r| import r }"
end
it { is_expected.to match(/# Defaults Capfile.*# App Defaults Capfile/m) }
it { is_expected.to include(load_recipes) }
end
end
end
context 'failure' do
context 'when no config_path context is passed' do
subject { described_class.call }
it { is_expected.to be_a_failure }
end
context 'when no application context is passed' do
subject { described_class.call(config_path: './my-conf') }
it { is_expected.to be_a_failure }
end
context 'when no cap_path context is passed' do
subject do
described_class.call(config_path: './my-conf', application: 'blog')
end
it { is_expected.to be_a_failure }
end
context 'when an exception is triggered' do
before { allow(FileUtils).to receive(:touch).and_raise(RuntimeError) }
it { is_expected.to be_a_failure }
end
context 'when passing a missing application' do
let(:args) do
{
config_path: RSpec.configuration.pulsar_conf_path,
cap_path: cap_path, application: 'wiki', applications: { 'blog' => %w(staging) }
}
end
it { is_expected.to be_a_failure }
context 'shows a proper error message' do
subject { command.error }
let(:error) do
'The application wiki does not exist in your repository'
end
it { is_expected.to be_an_instance_of Pulsar::ContextError }
it { expect(subject.message).to eql(error) }
end
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/cleanup_spec.rb | spec/units/interactors/cleanup_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::Cleanup do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.call' do
subject { FileUtils }
let(:run_path) { './some-path' }
before do
allow(subject).to receive(:rm_rf)
described_class.call(run_path: run_path)
end
it { is_expected.to have_received(:rm_rf).with(run_path) }
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/run_bundle_install_spec.rb | spec/units/interactors/run_bundle_install_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::RunBundleInstall do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.success' do
subject do
described_class.new(config_path: './config-path', bundle_path: './bundle-path')
end
let(:bundle_env) do
'BUNDLE_GEMFILE=./config-path/Gemfile BUNDLE_PATH=./bundle-path'
end
let(:bundle_install_cmd) do
"#{bundle_env} bundle check || #{bundle_env} bundle install"
end
before do
allow(Rake).to receive(:sh).and_return(true)
subject.run
end
it { expect(Rake).to have_received(:sh).with(bundle_install_cmd) }
end
context 'failure' do
context 'when no context is passed' do
subject { described_class.call }
it { is_expected.to be_a_failure }
end
context 'when no config_path context is passed' do
subject { described_class.call(bundle_path: './some-path') }
it { is_expected.to be_a_failure }
end
context 'when no bundle_path context is passed' do
subject { described_class.call(config_path: './some-path') }
it { is_expected.to be_a_failure }
end
context 'when an exception is triggered' do
subject do
described_class.new(config_path: './config-path', bundle_path: './bundle-path')
end
before do
allow(Rake).to receive(:sh).and_raise(RuntimeError)
subject.run
end
it { expect(subject.context).to be_a_failure }
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/interactors/identify_repository_type_spec.rb | spec/units/interactors/identify_repository_type_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::IdentifyRepositoryType do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor) }
describe '.call' do
subject { described_class.call(args) }
let(:repo) { './my-conf' }
let(:location) { :local }
let(:args) { { repository: repo, repository_location: location } }
context 'success' do
context 'when local' do
it { is_expected.to be_a_success }
context 'the configuration repository' do
subject { described_class.call(args).repository_type }
context 'is a folder' do
it { is_expected.to eql :folder }
end
end
end
context 'when remote' do
let(:location) { :remote }
it { is_expected.to be_a_success }
context 'the configuration repository' do
subject { described_class.call(args).repository_type }
context 'is a git repository' do
it { is_expected.to eql :git }
end
context 'is a GitHub repository' do
let(:repo) { 'github-account/my-conf' }
it { is_expected.to eql :github }
end
end
end
end
context 'failure' do
context 'when no repository context is passed' do
subject { described_class.call(repository_location: :local) }
it { is_expected.to be_a_failure }
end
context 'when no repository_location context is passed' do
subject { described_class.call(repository: repo) }
it { is_expected.to be_a_failure }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/organizers/install_spec.rb | spec/units/organizers/install_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::Install do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor::Organizer) }
context 'organizes interactors' do
subject { described_class.organized }
it { is_expected.to eql [Pulsar::CopyInitialRepository] }
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/organizers/list_spec.rb | spec/units/organizers/list_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::List do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor::Organizer) }
context 'organizes interactors' do
subject { described_class.organized }
let(:interactors) do
[
Pulsar::IdentifyRepositoryLocation,
Pulsar::IdentifyRepositoryType,
Pulsar::CreateRunDirs,
Pulsar::CloneRepository,
Pulsar::AddApplications,
Pulsar::Cleanup
]
end
it { is_expected.to eql interactors }
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/organizers/task_spec.rb | spec/units/organizers/task_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::Task do
subject { described_class.new }
it { is_expected.to be_kind_of(Interactor::Organizer) }
context 'organizes interactors' do
subject { described_class.organized }
let(:interactors) do
[
Pulsar::IdentifyRepositoryLocation,
Pulsar::IdentifyRepositoryType,
Pulsar::CreateRunDirs,
Pulsar::CloneRepository,
Pulsar::AddApplications,
Pulsar::CreateCapfile,
Pulsar::CreateDeployFile,
Pulsar::CopyEnvironmentFile,
Pulsar::RunBundleInstall,
Pulsar::RunCapistrano,
Pulsar::Cleanup
]
end
it { is_expected.to eql interactors }
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/cli/version_spec.rb | spec/units/cli/version_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CLI do
subject { Pulsar::Version }
let(:described_instance) { described_class.new }
context '#__print_version' do
subject { -> { described_instance.__print_version } }
it { is_expected.to output(/#{Pulsar::VERSION}/).to_stdout }
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/cli/install_spec.rb | spec/units/cli/install_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CLI do
subject { Pulsar::Install }
let(:described_instance) { described_class.new }
context '#install' do
let(:result) { spy }
before do
allow(Pulsar::Install).to receive(:call).and_return(result)
allow($stdout).to receive(:puts)
end
context 'calls Pulsar::Install with ./pulsar-conf by default' do
before { described_instance.install }
it { is_expected.to have_received(:call).with(directory: './pulsar-conf') }
end
context 'calls Pulsar::Install with an argument' do
before { described_instance.install('./a-dir') }
it { is_expected.to have_received(:call).with(directory: './a-dir') }
end
context 'success' do
subject { -> { described_instance.install } }
let(:result) { spy(success?: true) }
it { is_expected.to output(/Successfully created intial repo!/).to_stdout }
end
context 'failure' do
subject { -> { described_instance.install } }
let(:result) { spy(success?: false) }
it { is_expected.to output(/Failed to create intial repo./).to_stdout }
end
context 'when an error is reported' do
subject { -> { described_instance.install } }
before do
allow(described_instance).to receive(:options).and_return(conf_repo: repo)
described_instance.list
end
let(:repo) { RSpec.configuration.pulsar_conf_path }
context 'as a string' do
let(:result) { spy(success?: false, error: "A stub sets this error") }
it { is_expected.to output(/A stub sets this error/).to_stdout }
end
context 'as an exception object' do
let(:result) { spy(success?: false, error: RuntimeError.new("A stub sets this error")) }
it { is_expected.to output(/A stub sets this error/).to_stdout }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/cli/deploy_spec.rb | spec/units/cli/deploy_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CLI do
subject { Pulsar::Task }
let(:described_instance) { described_class.new }
let(:fail_text) { /Failed to deploy blog on production./ }
context '#deploy' do
let(:result) { spy }
let(:repo) { './conf_repo' }
before do
allow($stdout).to receive(:puts)
allow(Pulsar::Task).to receive(:call).and_return(result)
end
context 'when using --conf-repo' do
before do
allow(described_instance)
.to receive(:options).and_return(conf_repo: repo)
described_instance.deploy('blog', 'production')
end
specify do
is_expected.to have_received(:call)
.with(repository: repo, application: 'blog', environment: 'production', task: 'deploy')
end
context 'success' do
subject { -> { described_instance.deploy('blog', 'production') } }
let(:success) { "Deployed blog on production!" }
let(:result) { spy(success?: true) }
it { is_expected.to output(/#{success}/).to_stdout }
end
context 'failure' do
subject { -> { described_instance.deploy('blog', 'production') } }
let(:result) { spy(success?: false) }
it { is_expected.to output(fail_text).to_stdout }
end
end
context 'when using configuration file' do
let(:options) { {} }
before do
allow(described_instance).to receive(:options).and_return(options)
described_instance.deploy('blog', 'production')
end
around do |example|
old_const = Pulsar::PULSAR_CONF
Pulsar.send(:remove_const, 'PULSAR_CONF')
Pulsar::PULSAR_CONF = RSpec.configuration.pulsar_dotenv_conf_path
example.run
Pulsar.send(:remove_const, 'PULSAR_CONF')
Pulsar::PULSAR_CONF = old_const
end
specify do
is_expected.to have_received(:call)
.with(repository: repo, application: 'blog', environment: 'production', task: 'deploy')
end
context 'success' do
subject { -> { described_instance.deploy('blog', 'production') } }
let(:success) { "Deployed blog on production!" }
let(:result) { spy(success?: true) }
it { is_expected.to output(/#{success}/).to_stdout }
context 'when file is unaccessible' do
let(:options) { { conf_repo: repo } }
around do |example|
system("chmod 000 #{RSpec.configuration.pulsar_dotenv_conf_path}")
example.run
system("chmod 644 #{RSpec.configuration.pulsar_dotenv_conf_path}")
end
it { is_expected.to output(/#{success}/).to_stdout }
end
end
context 'failure' do
subject { -> { described_instance.deploy('blog', 'production') } }
let(:result) { spy(success?: false) }
it { is_expected.to output(fail_text).to_stdout }
end
end
context 'when using PULSAR_CONF_REPO' do
before do
allow(described_instance).to receive(:options).and_return({})
ENV['PULSAR_CONF_REPO'] = repo
described_instance.deploy('blog', 'production')
end
specify do
is_expected.to have_received(:call)
.with(repository: repo, application: 'blog', environment: 'production', task: 'deploy')
end
context 'success' do
subject { -> { described_instance.deploy('blog', 'production') } }
let(:success) { "Deployed blog on production!" }
let(:result) { spy(success?: true) }
it { is_expected.to output(/#{success}/).to_stdout }
end
context 'failure' do
subject { -> { described_instance.deploy('blog', 'production') } }
let(:result) { spy(success?: false) }
it { is_expected.to output(fail_text).to_stdout }
end
end
context 'when no configuration repo is passed' do
context 'failure' do
subject { -> { described_instance.deploy('blog', 'production') } }
it { is_expected.to raise_error(Thor::RequiredArgumentMissingError) }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/cli/list_spec.rb | spec/units/cli/list_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CLI do
subject { Pulsar::List }
let(:described_instance) { described_class.new }
let(:fail_text) { /Failed to list application and environments./ }
context '#list' do
let(:result) { spy }
let(:repo) { './conf_repo' }
before do
allow($stdout).to receive(:puts)
allow(Pulsar::List).to receive(:call).and_return(result)
end
context 'when using --conf-repo' do
before do
allow(described_instance)
.to receive(:options).and_return(conf_repo: repo)
described_instance.list
end
it { is_expected.to have_received(:call).with(repository: repo) }
context 'success' do
subject { -> { described_instance.list } }
let(:applications) { { 'blog' => %w(staging) } }
let(:result) { spy(success?: true, applications: applications) }
it { is_expected.to output(/blog: staging/).to_stdout }
end
context 'failure' do
subject { -> { described_instance.list } }
let(:result) { spy(success?: false) }
it { is_expected.to output(fail_text).to_stdout }
end
end
context 'when using configuration file' do
let(:options) { {} }
before do
allow(described_instance).to receive(:options).and_return(options)
described_instance.list
end
around do |example|
old_const = Pulsar::PULSAR_CONF
Pulsar.send(:remove_const, 'PULSAR_CONF')
Pulsar::PULSAR_CONF = RSpec.configuration.pulsar_dotenv_conf_path
example.run
Pulsar.send(:remove_const, 'PULSAR_CONF')
Pulsar::PULSAR_CONF = old_const
end
it { is_expected.to have_received(:call).with(repository: repo) }
context 'success' do
subject { -> { described_instance.list } }
let(:applications) { { 'blog' => %w(staging) } }
let(:result) { spy(success?: true, applications: applications) }
it { is_expected.to output(/blog: staging/).to_stdout }
context 'when file is unaccessible' do
let(:options) { { conf_repo: repo } }
around do |example|
system("chmod 000 #{RSpec.configuration.pulsar_dotenv_conf_path}")
example.run
system("chmod 644 #{RSpec.configuration.pulsar_dotenv_conf_path}")
end
it { is_expected.to output(/blog: staging/).to_stdout }
end
end
context 'failure' do
subject { -> { described_instance.list } }
let(:result) { spy(success?: false) }
it { is_expected.to output(fail_text).to_stdout }
end
end
context 'when using PULSAR_CONF_REPO' do
before do
allow(described_instance).to receive(:options).and_return({})
ENV['PULSAR_CONF_REPO'] = repo
described_instance.list
end
it { is_expected.to have_received(:call).with(repository: repo) }
context 'success' do
subject { -> { described_instance.list } }
let(:applications) { { 'blog' => %w(staging) } }
let(:result) { spy(success?: true, applications: applications) }
it { is_expected.to output(/blog: staging/).to_stdout }
end
context 'failure' do
subject { -> { described_instance.list } }
let(:result) { spy(success?: false) }
it { is_expected.to output(fail_text).to_stdout }
end
end
context 'when no configuration repo is passed' do
context 'failure' do
subject { -> { described_instance.deploy('blog', 'production') } }
it { is_expected.to raise_error(Thor::RequiredArgumentMissingError) }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/units/cli/task_spec.rb | spec/units/cli/task_spec.rb | require 'spec_helper'
RSpec.describe Pulsar::CLI do
subject { Pulsar::Task }
let(:described_instance) { described_class.new }
let(:fail_text) { /Failed to execute task deploy:check for blog on production./ }
context '#task' do
let(:result) { spy }
let(:repo) { './conf_repo' }
before do
allow($stdout).to receive(:puts)
allow(Pulsar::Task).to receive(:call).and_return(result)
end
context 'when using --conf-repo' do
before do
allow(described_instance)
.to receive(:options).and_return(conf_repo: repo)
described_instance.task('blog', 'production', 'deploy:check')
end
specify do
is_expected.to have_received(:call)
.with(repository: repo, application: 'blog', environment: 'production', task: 'deploy:check')
end
context 'success' do
subject { -> { described_instance.task('blog', 'production', 'deploy:check') } }
let(:success) { "Executed task deploy:check for blog on production!" }
let(:result) { spy(success?: true) }
it { is_expected.to output(/#{success}/).to_stdout }
end
context 'failure' do
subject { -> { described_instance.task('blog', 'production', 'deploy:check') } }
let(:result) { spy(success?: false) }
it { is_expected.to output(fail_text).to_stdout }
end
end
context 'when using configuration file' do
let(:options) { {} }
before do
allow(described_instance).to receive(:options).and_return(options)
described_instance.task('blog', 'production', 'deploy:check')
end
around do |example|
old_const = Pulsar::PULSAR_CONF
Pulsar.send(:remove_const, 'PULSAR_CONF')
Pulsar::PULSAR_CONF = RSpec.configuration.pulsar_dotenv_conf_path
example.run
Pulsar.send(:remove_const, 'PULSAR_CONF')
Pulsar::PULSAR_CONF = old_const
end
specify do
is_expected.to have_received(:call)
.with(repository: repo, application: 'blog', environment: 'production', task: 'deploy:check')
end
context 'success' do
subject { -> { described_instance.task('blog', 'production', 'deploy:check') } }
let(:success) { "Executed task deploy:check for blog on production!" }
let(:result) { spy(success?: true) }
it { is_expected.to output(/#{success}/).to_stdout }
context 'when file is unaccessible' do
let(:options) { { conf_repo: repo } }
around do |example|
system("chmod 000 #{RSpec.configuration.pulsar_dotenv_conf_path}")
example.run
system("chmod 644 #{RSpec.configuration.pulsar_dotenv_conf_path}")
end
it { is_expected.to output(/#{success}/).to_stdout }
end
end
context 'failure' do
subject { -> { described_instance.task('blog', 'production', 'deploy:check') } }
let(:result) { spy(success?: false) }
it { is_expected.to output(fail_text).to_stdout }
end
end
context 'when using PULSAR_CONF_REPO' do
before do
allow(described_instance).to receive(:options).and_return({})
ENV['PULSAR_CONF_REPO'] = repo
described_instance.task('blog', 'production', 'deploy:check')
end
specify do
is_expected.to have_received(:call)
.with(repository: repo, application: 'blog', environment: 'production', task: 'deploy:check')
end
context 'success' do
subject { -> { described_instance.task('blog', 'production', 'deploy:check') } }
let(:success) { "Executed task deploy:check for blog on production!" }
let(:result) { spy(success?: true) }
it { is_expected.to output(/#{success}/).to_stdout }
end
context 'failure' do
subject { -> { described_instance.task('blog', 'production', 'deploy:check') } }
let(:result) { spy(success?: false) }
it { is_expected.to output(fail_text).to_stdout }
end
end
context 'when no configuration repo is passed' do
context 'failure' do
subject { -> { described_instance.task('blog', 'production', 'deploy:check') } }
it { is_expected.to raise_error(Thor::RequiredArgumentMissingError) }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/features/version_spec.rb | spec/features/version_spec.rb | require 'spec_helper'
RSpec.describe 'Version' do
subject { command }
let(:command) do
`#{RSpec.configuration.pulsar_command} #{arguments}`
end
let(:arguments) { "--version" }
context 'via a --version flag' do
let(:version) { "#{Pulsar::VERSION}\n" }
it { is_expected.to eql version }
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/features/install_spec.rb | spec/features/install_spec.rb | require 'spec_helper'
RSpec.describe 'Install' do
subject { command }
let(:command) do
`#{RSpec.configuration.pulsar_command} install #{arguments}`
end
let(:arguments) { nil }
context 'via a subcommand named install' do
subject { -> { command } }
let(:error) { /Could not find command/ }
it { is_expected.not_to output(error).to_stderr_from_any_process }
end
context 'when succeeds' do
it { is_expected.to eql "Successfully created intial repo!\n" }
context 'creates a directory' do
subject { -> { command } }
context 'with the basic configuration' do
subject(:initial_pulsar_repo) do
Dir.entries('./../../../lib/pulsar/generators/initial_repo/')
end
before { command }
it 'contains the initial directory structure' do
is_expected.to eql Dir.entries('./pulsar-conf')
end
end
context 'inside the current directory by default' do
it 'named pulsar-conf' do
is_expected
.to change { File.exist?('./pulsar-conf') }.from(false).to(true)
end
end
context 'inside a directory passed as argument' do
let(:arguments) { './my-dir' }
it 'named as the argument' do
is_expected.to change { File.exist?('./my-dir') }.from(false).to(true)
end
end
end
end
context 'when fails' do
let(:arguments) { '/pulsar-conf' }
it { is_expected.to match "Failed to create intial repo.\n" }
context 'does not create a directory' do
subject { -> { command } }
it { is_expected.not_to change { File.exist?('./my-dir') }.from(false) }
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/features/deploy_spec.rb | spec/features/deploy_spec.rb | require 'spec_helper'
RSpec.describe 'Deploy' do
subject { -> { command } }
let(:command) do
`DRY_RUN=true #{RSpec.configuration.pulsar_command} deploy #{options} #{arguments}`
end
let(:repo) { RSpec.configuration.pulsar_conf_path }
let(:options) { "--conf-repo #{repo}" }
let(:app) { 'blog' }
let(:environment) { 'production' }
let(:arguments) { "#{app} #{environment}" }
context 'via a subcommand named deploy' do
let(:error) { /Could not find command/ }
it { is_expected.not_to output(error).to_stderr_from_any_process }
end
context 'requires a --conf-repo option' do
let(:options) { nil }
let(:error) { /No value provided for required options '--conf-repo'/ }
it { is_expected.to output(error).to_stderr_from_any_process }
context 'can be specified via the alias -c' do
let(:options) { "-c #{repo}" }
it { is_expected.not_to output(error).to_stderr_from_any_process }
end
context 'can be specified via the environment variable PULSAR_CONF_REPO' do
before { ENV['PULSAR_CONF_REPO'] = repo }
it { is_expected.not_to output(error).to_stderr_from_any_process }
end
end
context 'requires application and environment arguments' do
let(:app) { nil }
let(:environment) { nil }
let(:error) { /Usage: "pulsar deploy APPLICATION ENVIRONMENT"/ }
it { is_expected.to output(error).to_stderr_from_any_process }
end
context 'when succeeds' do
subject { command }
context 'deploys an application on a environment in the pulsar configuration' do
let(:output) { "Deployed blog on production!\n" }
context 'from a local folder' do
let(:repo) { Dir.mktmpdir }
before do
FileUtils.cp_r("#{RSpec.configuration.pulsar_conf_path}/.", repo)
end
it { is_expected.to match(output) }
context 'leaves the tmp folder empty' do
subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
before { command }
it { is_expected.to be_empty }
end
end
context 'from a remote Git repository' do
let(:repo) { RSpec.configuration.pulsar_remote_git_conf }
let(:app) { 'your_app' }
let(:environment) { 'staging' }
let(:output) { "Deployed your_app on staging!\n" }
it { is_expected.to match(output) }
context 'leaves the tmp folder empty' do
subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
before { command }
it { is_expected.to be_empty }
end
end
context 'from a remote GitHub repository' do
let(:repo) { RSpec.configuration.pulsar_remote_github_conf }
let(:app) { 'your_app' }
let(:environment) { 'staging' }
let(:output) { "Deployed your_app on staging!\n" }
it { is_expected.to match(output) }
context 'leaves the tmp folder empty' do
subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
before { command }
it { is_expected.to be_empty }
end
end
end
end
context 'when fails' do
subject { command }
context 'because of wrong directory' do
let(:repo) { './some-wrong-directory' }
it { is_expected.to match("Failed to deploy blog on production.\n") }
end
context 'because of empty directory' do
let(:repo) { RSpec.configuration.pulsar_empty_conf_path }
it { is_expected.to match("Failed to deploy blog on production.\n") }
it { is_expected.to match "No application found on repository #{RSpec.configuration.pulsar_empty_conf_path}\n" }
end
context 'because Bundler failed' do
let(:repo) { RSpec.configuration.pulsar_wrong_bundle_conf_path }
it { is_expected.to match("Failed to deploy blog on production.\n") }
end
context 'because Capistrano failed' do
let(:repo) { RSpec.configuration.pulsar_wrong_cap_conf_path }
it { is_expected.to match("Failed to deploy blog on production.\n") }
end
context 'because the application does not exists in the repository' do
let(:repo) { RSpec.configuration.pulsar_conf_path }
let(:app) { 'foobuzz' }
let(:environment) { 'staging' }
it { is_expected.to match("The application foobuzz does not exist in your repository") }
end
context 'because the environment does not exists for the application' do
let(:repo) { RSpec.configuration.pulsar_conf_path }
let(:app) { 'blog' }
let(:environment) { 'foobuzz' }
it { is_expected.to match("The application blog does not have an environment called foobuzz") }
context 'but \'no application error\' message takes precedence' do
let(:app) { 'foobuzz' }
it { is_expected.to match("The application foobuzz does not exist in your repository") }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/features/list_spec.rb | spec/features/list_spec.rb | require 'spec_helper'
RSpec.describe 'List' do
subject { -> { command } }
let(:command) do
`#{RSpec.configuration.pulsar_command} list #{arguments}`
end
let(:repo) { RSpec.configuration.pulsar_conf_path }
let(:arguments) { "--conf-repo #{repo}" }
context 'via a subcommand named list' do
let(:error) { /Could not find command/ }
it { is_expected.not_to output(error).to_stderr_from_any_process }
end
context 'requires a --conf-repo option' do
let(:arguments) { nil }
let(:error) { /No value provided for required options '--conf-repo'/ }
it { is_expected.to output(error).to_stderr_from_any_process }
context 'can be specified via the alias -c' do
let(:arguments) { "-c #{repo}" }
it { is_expected.not_to output(error).to_stderr_from_any_process }
end
context 'can be specified via the environment variable PULSAR_CONF_REPO' do
before { ENV['PULSAR_CONF_REPO'] = repo }
it { is_expected.not_to output(error).to_stderr_from_any_process }
end
end
context 'when succeeds' do
subject { command }
context 'lists applications in the pulsar configuration' do
let(:output) { "blog: production, staging\necommerce: staging\n" }
context 'from a local folder' do
let(:repo) { Dir.mktmpdir }
before do
FileUtils.cp_r("#{RSpec.configuration.pulsar_conf_path}/.", repo)
end
it { is_expected.to eql(output) }
context 'leaves the tmp folder empty' do
subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
before { command }
it { is_expected.to be_empty }
end
end
context 'from a remote Git repository' do
let(:repo) { RSpec.configuration.pulsar_remote_git_conf }
let(:output) { "your_app: production, staging\n" }
it { is_expected.to eql output }
context 'leaves the tmp folder empty' do
subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
before { command }
it { is_expected.to be_empty }
end
end
context 'from a remote GitHub repository' do
let(:repo) { RSpec.configuration.pulsar_remote_github_conf }
let(:output) { "your_app: production, staging\n" }
it { is_expected.to eql output }
context 'leaves the tmp folder empty' do
subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
before { command }
it { is_expected.to be_empty }
end
end
end
end
context 'when fails' do
subject { command }
context 'because of wrong directory' do
let(:repo) { './some-wrong-directory' }
it { is_expected.to match "Failed to list application and environments.\n" }
end
context 'because of empty directory' do
let(:repo) { RSpec.configuration.pulsar_empty_conf_path }
it { is_expected.to match "Failed to list application and environments.\n" }
it { is_expected.to match "No application found on repository #{RSpec.configuration.pulsar_empty_conf_path}\n" }
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/spec/features/task_spec.rb | spec/features/task_spec.rb | require 'spec_helper'
RSpec.describe 'Task' do
subject { -> { command } }
let(:command) do
`DRY_RUN=true #{RSpec.configuration.pulsar_command} task #{options} #{arguments} #{task}`
end
let(:repo) { RSpec.configuration.pulsar_conf_path }
let(:task) { 'deploy:check' }
let(:options) { "--conf-repo #{repo}" }
let(:app) { 'blog' }
let(:environment) { 'production' }
let(:arguments) { "#{app} #{environment}" }
context 'via a subcommand named task' do
let(:error) { /Could not find command/ }
it { is_expected.not_to output(error).to_stderr_from_any_process }
end
context 'requires a --conf-repo option' do
let(:options) { nil }
let(:error) { /No value provided for required options '--conf-repo'/ }
it { is_expected.to output(error).to_stderr_from_any_process }
context 'can be specified via the alias -c' do
let(:options) { "-c #{repo}" }
it { is_expected.not_to output(error).to_stderr_from_any_process }
end
context 'can be specified via the environment variable PULSAR_CONF_REPO' do
before { ENV['PULSAR_CONF_REPO'] = repo }
it { is_expected.not_to output(error).to_stderr_from_any_process }
end
end
context 'requires application and environment arguments' do
let(:app) { nil }
let(:environment) { nil }
let(:error) { /Usage: "pulsar task APPLICATION ENVIRONMENT TASK"/ }
it { is_expected.to output(error).to_stderr_from_any_process }
end
context 'when succeeds' do
subject { command }
context 'deploys an application on a environment in the pulsar configuration' do
let(:output) { /Executed task deploy:check for blog on production!/ }
context 'from a local folder' do
let(:repo) { Dir.mktmpdir }
before do
FileUtils.cp_r("#{RSpec.configuration.pulsar_conf_path}/.", repo)
end
context 'with Capistrano parameters passed via command line' do
let(:task) { "deploy:check[param1,param2]" }
let(:output) { /Executed task deploy:check\[param1,param2\] for blog on production!\n/ }
it { is_expected.to match(output) }
end
context 'without Capistrano parameters' do
it { is_expected.to match(output) }
end
context 'leaves the tmp folder empty' do
subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
before { command }
it { is_expected.to be_empty }
end
end
context 'from a remote Git repository' do
let(:repo) { RSpec.configuration.pulsar_remote_git_conf }
let(:app) { 'your_app' }
let(:environment) { 'staging' }
let(:output) { /Executed task deploy:check for your_app on staging!\n/ }
context 'with Capistrano parameters passed via command line' do
let(:task) { "deploy:check[param1,param2]" }
let(:output) { /Executed task deploy:check\[param1,param2\] for your_app on staging!\n/ }
it { is_expected.to match(output) }
end
context 'without Capistrano parameters' do
it { is_expected.to match(output) }
end
context 'leaves the tmp folder empty' do
subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
before { command }
it { is_expected.to be_empty }
end
end
context 'from a remote GitHub repository' do
let(:repo) { RSpec.configuration.pulsar_remote_github_conf }
let(:app) { 'your_app' }
let(:environment) { 'staging' }
let(:output) { /Executed task deploy:check for your_app on staging!\n/ }
context 'with Capistrano parameters passed via command line' do
let(:task) { "deploy:check[param1,param2]" }
let(:output) { /Executed task deploy:check\[param1,param2\] for your_app on staging!\n/ }
it { is_expected.to match(output) }
end
context 'without Capistrano parameters' do
it { is_expected.to match(output) }
end
context 'leaves the tmp folder empty' do
subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
before { command }
it { is_expected.to be_empty }
end
end
end
end
context 'when fails' do
subject { command }
context 'because of wrong directory' do
let(:repo) { './some-wrong-directory' }
it { is_expected.to match(/Failed to execute task deploy:check for blog on production.\n/) }
end
context 'because of empty directory' do
let(:repo) { RSpec.configuration.pulsar_empty_conf_path }
it { is_expected.to match(/Failed to execute task deploy:check for blog on production.\n/) }
it { is_expected.to match "No application found on repository #{RSpec.configuration.pulsar_empty_conf_path}\n" }
end
context 'because Bundler failed' do
let(:repo) { RSpec.configuration.pulsar_wrong_bundle_conf_path }
it { is_expected.to match(/Failed to execute task deploy:check for blog on production.\n/) }
end
context 'because Capistrano failed' do
let(:repo) { RSpec.configuration.pulsar_wrong_cap_conf_path }
it { is_expected.to match(/Failed to execute task deploy:check for blog on production.\n/) }
end
context 'because the application does not exists in the repository' do
let(:repo) { RSpec.configuration.pulsar_conf_path }
let(:app) { 'foobuzz' }
let(:environment) { 'staging' }
it { is_expected.to match(/The application foobuzz does not exist in your repository/) }
end
context 'because the environment does not exists for the application' do
let(:repo) { RSpec.configuration.pulsar_conf_path }
let(:app) { 'blog' }
let(:environment) { 'foobuzz' }
it { is_expected.to match(/The application blog does not have an environment called foobuzz/) }
context 'but \'no application error\' message takes precedence' do
let(:app) { 'foobuzz' }
it { is_expected.to match(/The application foobuzz does not exist in your repository/) }
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar.rb | lib/pulsar.rb | require 'pulsar/version'
module Pulsar
require 'bundler'
require 'thor'
require 'rake'
require 'dotenv'
require 'interactor'
require 'fileutils'
require 'pulsar/context_error'
require 'pulsar/validator'
require 'pulsar/interactors/cleanup'
require 'pulsar/interactors/create_run_dirs'
require 'pulsar/interactors/add_applications'
require 'pulsar/interactors/clone_repository'
require 'pulsar/interactors/copy_initial_repository'
require 'pulsar/interactors/identify_repository_type'
require 'pulsar/interactors/identify_repository_location'
require 'pulsar/interactors/create_capfile'
require 'pulsar/interactors/create_deploy_file'
require 'pulsar/interactors/copy_environment_file'
require 'pulsar/interactors/run_bundle_install'
require 'pulsar/interactors/run_capistrano'
require 'pulsar/organizers/list'
require 'pulsar/organizers/install'
require 'pulsar/organizers/task'
require 'pulsar/constants'
require 'pulsar/cli'
# Silence Rake output
Rake::FileUtilsExt.verbose_flag = false
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/version.rb | lib/pulsar/version.rb | module Pulsar
VERSION = '1.1.0'.freeze
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/constants.rb | lib/pulsar/constants.rb | module Pulsar
PULSAR_HOME = File.expand_path('~/.pulsar')
PULSAR_TMP = "#{PULSAR_HOME}/tmp".freeze
PULSAR_CONF = "#{PULSAR_HOME}/config".freeze
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/validator.rb | lib/pulsar/validator.rb | module Pulsar
module Validator
def self.included(klass)
klass.extend ClassMethods
klass.before :validate_context!
end
def validate_context!
validable_properties.each do |property|
result = context.send property.to_sym
context_fail! "Invalid context for #{property} [#{result}]" unless result
end
end
def context_fail!(msg)
context.fail! error: Pulsar::ContextError.new(msg)
end
def validable_properties
self.class.validable_properties
end
module ClassMethods
def validate_context_for!(*args)
validable_properties.concat args
end
def validable_properties
@validable_properties ||= []
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/cli.rb | lib/pulsar/cli.rb | if ENV['COVERAGE']
ENV['FEATURE_TESTS'] = 'true'
require_relative '../../spec/support/coverage_setup'
end
module Pulsar
class CLI < Thor
map %w[--version -v] => :__print_version
desc 'install [DIRECTORY]', 'Install initial repository in DIRECTORY'
long_desc <<-LONGDESC
`pulsar install` will install the initial pulsar repository in the
current working directory.
You can optionally specify a second parameter, which will be the
destination directory in which to install the repository.
LONGDESC
def install(directory = './pulsar-conf')
result = Pulsar::Install.call(directory: directory)
if result.success?
puts 'Successfully created intial repo!'
else
puts 'Failed to create intial repo.'
puts result.error
end
end
desc 'list', 'List available applications and environments'
long_desc <<-LONGDESC
`pulsar list` will list the applications and environments available in
the configured pulsar repository.
LONGDESC
option :conf_repo, aliases: '-c'
def list
load_config
result = Pulsar::List.call(repository: load_option_or_env!(:conf_repo))
if result.success?
result.applications.each do |app, stages|
puts "#{app}: #{stages.join(', ')}"
end
else
puts 'Failed to list application and environments.'
puts result.error
end
end
desc 'deploy APPLICATION ENVIRONMENT', 'Run Capistrano to deploy APPLICATION on ENVIRONMENT'
long_desc <<-LONGDESC
`pulsar deploy APPLICATION ENVIRONMENT` will generate the configuration for the
specified APPLICATION on ENVIRONMENT from the configuration repo and run
Capistrano on it.
LONGDESC
option :conf_repo, aliases: '-c'
def deploy(application, environment)
load_config
result = Pulsar::Task.call(
repository: load_option_or_env!(:conf_repo),
application: application, environment: environment,
task: 'deploy'
)
if result.success?
puts "Deployed #{application} on #{environment}!"
else
puts "Failed to deploy #{application} on #{environment}."
puts result.error
end
end
desc 'task APPLICATION ENVIRONMENT TASK', 'Run Capistrano task for APPLICATION on ENVIRONMENT'
option :conf_repo, aliases: '-c'
def task(application, environment, task)
load_config
result = Pulsar::Task.call(
repository: load_option_or_env!(:conf_repo),
application: application, environment: environment,
task: task
)
if result.success?
puts "Executed task #{task} for #{application} on #{environment}!"
else
puts "Failed to execute task #{task} for #{application} on #{environment}."
puts result.error
end
end
desc "--version, -v", "print the version"
def __print_version
puts Pulsar::VERSION
end
private
def load_config
return unless File.exist?(PULSAR_CONF) && File.stat(PULSAR_CONF).readable?
Dotenv.load(PULSAR_CONF) # Load configurations for Pulsar
end
def load_option_or_env!(option)
option_name = "--#{option.to_s.tr!('_', '-')}"
env_option = "PULSAR_#{option.upcase}"
exception_text = "No value provided for required options '#{option_name}'"
option_value = options[option] || ENV[env_option]
if option_value.nil? || option_value.empty?
fail RequiredArgumentMissingError, exception_text
end
option_value
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/context_error.rb | lib/pulsar/context_error.rb | module Pulsar
class ContextError < StandardError
def to_s
backtrace ? backtrace.unshift(super).join("\n") : super
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/identify_repository_location.rb | lib/pulsar/interactors/identify_repository_location.rb | module Pulsar
class IdentifyRepositoryLocation
include Interactor
include Pulsar::Validator
def call
context.repository_location = if File.exist?(context.repository)
:local
else
:remote
end
rescue
context_fail! $!.message
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/create_capfile.rb | lib/pulsar/interactors/create_capfile.rb | module Pulsar
class CreateCapfile
include Interactor
include Pulsar::Validator
validate_context_for! :config_path, :cap_path, :application, :applications
before :validate_application!, :prepare_context
def call
default_capfile = "#{context.config_path}/apps/Capfile"
app_capfile = "#{context.config_path}/apps/#{context.application}/Capfile"
import_tasks = "Dir.glob(\"#{context.config_path}/recipes/**/*.rake\").each { |r| import r }"
FileUtils.touch(context.capfile_path)
Rake.sh("cat #{default_capfile} >> #{context.capfile_path}") if File.exist?(default_capfile)
Rake.sh("cat #{app_capfile} >> #{context.capfile_path}") if File.exist?(app_capfile)
Rake.sh("echo '#{import_tasks}' >> #{context.capfile_path}")
rescue
context_fail! $!.message
end
private
def prepare_context
context.capfile_path = "#{context.cap_path}/Capfile"
end
def validate_application!
fail_on_missing_application! unless application_exists?
end
def application_exists?
context.applications.keys.include? context.application
end
def fail_on_missing_application!
context_fail! "The application #{context.application} does not exist in your repository"
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/run_bundle_install.rb | lib/pulsar/interactors/run_bundle_install.rb | module Pulsar
class RunBundleInstall
include Interactor
include Pulsar::Validator
validate_context_for! :config_path, :bundle_path
def call
gemfile_env = "BUNDLE_GEMFILE=#{context.config_path}/Gemfile"
bundle_env = "BUNDLE_PATH=#{context.bundle_path}"
cmd_env = "#{gemfile_env} #{bundle_env}"
out_redir = ENV['DRY_RUN'] ? '> /dev/null 2>&1' : nil
bundle_cmd = "#{cmd_env} bundle check || #{cmd_env} bundle install"
Bundler.with_clean_env do
Rake.sh("#{bundle_cmd}#{out_redir}")
end
rescue
context_fail! $!.message
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/cleanup.rb | lib/pulsar/interactors/cleanup.rb | module Pulsar
class Cleanup
include Interactor
include Pulsar::Validator
def call
FileUtils.rm_rf(context.run_path)
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/run_capistrano.rb | lib/pulsar/interactors/run_capistrano.rb | module Pulsar
class RunCapistrano
include Interactor
include Pulsar::Validator
validate_context_for! :cap_path, :config_path, :bundle_path, :environment
def call
Dir.chdir(context.cap_path) do
gemfile_env = "BUNDLE_GEMFILE=#{context.config_path}/Gemfile"
bundle_env = "BUNDLE_PATH=#{context.bundle_path}"
cap_opts = ENV['DRY_RUN'] ? '--dry-run ' : nil
out_redir = ENV['DRY_RUN'] ? '> /dev/null 2>&1' : nil
cap_cmd = "bundle exec cap #{cap_opts}#{context.environment} #{context.task}"
Rake.sh("#{gemfile_env} #{bundle_env} #{cap_cmd}#{out_redir}")
end
rescue
context_fail! $!.message
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/copy_environment_file.rb | lib/pulsar/interactors/copy_environment_file.rb | module Pulsar
class CopyEnvironmentFile
include Interactor
include Pulsar::Validator
validate_context_for! :config_path, :cap_path, :application, :applications
before :validate_environment!
before :prepare_context
def call
env_file = "#{context.config_path}/apps/#{context.application}/#{context.environment}.rb"
FileUtils.mkdir_p(context.cap_deploy_path)
FileUtils.cp(env_file, context.environment_file_path)
rescue
context_fail! $!.message
end
private
def prepare_context
context.cap_deploy_path = "#{context.cap_path}/config/deploy"
context.environment_file_path = "#{context.cap_deploy_path}/#{context.environment}.rb"
end
def validate_environment!
fail_on_missing_environment! unless environment_exist?
end
def environment_exist?
context.applications[context.application].include?(context.environment)
end
def fail_on_missing_environment!
context_fail! "The application #{context.application} does not have an environment called #{context.environment}"
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/copy_initial_repository.rb | lib/pulsar/interactors/copy_initial_repository.rb | module Pulsar
class CopyInitialRepository
include Interactor
include Pulsar::Validator
def call
current_path = File.dirname(__FILE__)
initial_repo = "#{current_path}/../generators/initial_repo"
FileUtils.cp_r(File.expand_path(initial_repo), context.directory)
rescue
context_fail! $!.message
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/create_deploy_file.rb | lib/pulsar/interactors/create_deploy_file.rb | module Pulsar
class CreateDeployFile
include Interactor
include Pulsar::Validator
before :prepare_context
def call
default_deploy = "#{context.config_path}/apps/deploy.rb"
app_deploy = "#{context.config_path}/apps/#{context.application}/deploy.rb"
FileUtils.mkdir_p(context.cap_config_path)
FileUtils.touch(context.deploy_file_path)
Rake.sh("cat #{default_deploy} >> #{context.deploy_file_path}") if File.exist?(default_deploy)
Rake.sh("cat #{app_deploy} >> #{context.deploy_file_path}") if File.exist?(app_deploy)
rescue
context_fail!$!.message
end
private
def prepare_context
context.cap_config_path = "#{context.cap_path}/config"
context.deploy_file_path = "#{context.cap_config_path}/deploy.rb"
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/create_run_dirs.rb | lib/pulsar/interactors/create_run_dirs.rb | module Pulsar
class CreateRunDirs
include Interactor
include Pulsar::Validator
def call
context.timestamp = Time.now.to_f
context.bundle_path = "#{PULSAR_HOME}/bundle"
context.run_path = "#{PULSAR_TMP}/run-#{context.timestamp}"
context.config_path = "#{context.run_path}/conf"
context.cap_path = "#{context.run_path}/cap"
FileUtils.mkdir_p(context.bundle_path)
FileUtils.mkdir_p(context.config_path)
FileUtils.mkdir_p(context.cap_path)
end
def rollback
FileUtils.rm_rf(context.run_path)
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/add_applications.rb | lib/pulsar/interactors/add_applications.rb | module Pulsar
class AddApplications
include Interactor
include Pulsar::Validator
validate_context_for! :config_path
before :prepare_context
after :validate_output!
def call
each_application_path do |app|
context.applications[File.basename(app)] = stages_for(app)
end
rescue
context_fail! $!.message
end
private
def prepare_context
context.applications = {}
end
def validate_output!
context_fail! "No application found on repository #{context.repository}" if context.applications.empty?
end
def each_application_path
Dir["#{context.config_path}/apps/*"].sort.each do |app|
next if File.basename(app, '.rb') == 'deploy' ||
File.basename(app) == 'Capfile'
yield(app)
end
end
def stages_for(app)
stage_files = Dir["#{app}/*.rb"].sort.map do |file|
File.basename(file, '.rb')
end
stage_files.reject do |stage|
%w(deploy Capfile).include?(stage)
end
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/identify_repository_type.rb | lib/pulsar/interactors/identify_repository_type.rb | module Pulsar
class IdentifyRepositoryType
include Interactor
include Pulsar::Validator
validate_context_for! :repository, :repository_location
def call
case context.repository_location
when :local
context.repository_type = :folder
when :remote
context.repository_type = github_repository? ? :github : :git
end
end
private
def github_repository?
context.repository =~ %r{^[\w-]+\/[\w-]+$}
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/interactors/clone_repository.rb | lib/pulsar/interactors/clone_repository.rb | module Pulsar
class CloneRepository
include Interactor
include Pulsar::Validator
validate_context_for! :config_path, :repository, :repository_type
def call
case context.repository_type
when :git then clone_git_repository
when :github then clone_github_repository
when :folder then copy_local_folder
end
rescue
context_fail! $!.message
end
private
def clone_git_repository
cmd = 'git clone'
opts = '--quiet --depth 1'
quiet = '>/dev/null 2>&1'
Rake.sh(
"#{cmd} #{opts} #{context.repository} #{context.config_path} #{quiet}"
)
end
def clone_github_repository
cmd = 'git clone'
opts = '--quiet --depth 1'
quiet = '>/dev/null 2>&1'
repo = "git@github.com:#{context.repository}.git"
Rake.sh(
"#{cmd} #{opts} #{repo} #{context.config_path} #{quiet}"
)
end
def copy_local_folder
raise "No repository found at #{context.repository}" unless File.exist? context.repository
FileUtils.cp_r("#{context.repository}/.", context.config_path)
end
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/generators/initial_repo/apps/deploy.rb | lib/pulsar/generators/initial_repo/apps/deploy.rb | # deploy.rb file shared between all the apps
# config valid only for current version of Capistrano
lock '3.8.0'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name'
# Default value for :scm is :git
# set :scm, :git
# Default value for :format is :airbrussh.
# set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
# append :linked_files, 'config/database.yml', 'config/secrets.yml'
# Default value for linked_dirs is []
# append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system'
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
# set :keep_releases, 5
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/generators/initial_repo/apps/your_app/staging.rb | lib/pulsar/generators/initial_repo/apps/your_app/staging.rb | server 'staging.your_app.com', user: 'deploy', roles: %w{web app db}, primary: true
set :stage, :staging
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/generators/initial_repo/apps/your_app/production.rb | lib/pulsar/generators/initial_repo/apps/your_app/production.rb | server 'your_app.com', user: 'deploy', roles: %w{web app db}, primary: true
set :stage, :production
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/generators/initial_repo/apps/your_app/deploy.rb | lib/pulsar/generators/initial_repo/apps/your_app/deploy.rb | # deploy.rb file shared between all the stages of a certain app
set :application, 'my_app_name'
set :repo_url, 'git@example.com:me/my_repo.git'
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/organizers/task.rb | lib/pulsar/organizers/task.rb | module Pulsar
class Task
include Interactor::Organizer
organize IdentifyRepositoryLocation,
IdentifyRepositoryType,
CreateRunDirs,
CloneRepository,
AddApplications,
CreateCapfile,
CreateDeployFile,
CopyEnvironmentFile,
RunBundleInstall,
RunCapistrano,
Cleanup
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/organizers/list.rb | lib/pulsar/organizers/list.rb | module Pulsar
class List
include Interactor::Organizer
organize IdentifyRepositoryLocation,
IdentifyRepositoryType,
CreateRunDirs,
CloneRepository,
AddApplications,
Cleanup
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
nebulab/pulsar | https://github.com/nebulab/pulsar/blob/fd8d081653f70517e0d40e71611aede8814ab1d8/lib/pulsar/organizers/install.rb | lib/pulsar/organizers/install.rb | module Pulsar
class Install
include Interactor::Organizer
organize CopyInitialRepository
end
end
| ruby | MIT | fd8d081653f70517e0d40e71611aede8814ab1d8 | 2026-01-04T17:51:14.324688Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/sft_segment_spec.rb | spec/sft_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::SFT do
context "general" do
before :all do
@base_sft = "SFT|Level Seven Healthcare Software, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1.2|An Lab System|56734||20080817"
end
it "creates an SFT segment" do
expect do
sft = HL7::Message::Segment::SFT.new(@base_sft)
expect(sft).not_to be_nil
expect(sft.to_s).to eq @base_sft
end.not_to raise_error
end
it "allows access to an SFT segment" do
expect do
sft = HL7::Message::Segment::SFT.new(@base_sft)
expect(sft.software_product_name).to eq "An Lab System"
expect(sft.software_install_date).to eq "20080817"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/dynamic_segment_def_spec.rb | spec/dynamic_segment_def_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe "dynamic segment definition" do
context "general" do
it "accepts a block with a parameter" do
seg = HL7::Message::Segment.new do |s|
s.e0 = "MSK"
s.e1 = "1234"
s.e2 = "5678"
end
expect(seg.to_s).to eq "MSK|1234|5678"
end
it "accepts a block without a parameter" do
seg = HL7::Message::Segment.new do
e0 "MSK"
e1 "1234"
e2 "5678"
end
expect(seg.to_s).to eq "MSK|1234|5678"
end
it "doesn't pollute the caller namespace" do
seg = HL7::Message::Segment.new do |s|
s.e0 = "MSK"
s.e1 = "1234"
s.e2 = "5678"
end
expect { e3 "TEST" }.to raise_error(NoMethodError)
expect(seg.to_s).to eq "MSK|1234|5678"
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/segment_spec.rb | spec/segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment do
describe "length" do
it "returns the length of the elements" do
segment = HL7::Message::Segment.new "MSA|AR|ZZ9380 ERR"
expect(segment.length).to eq 3
end
end
describe "enumerable" do
it "enumerates over elements" do
seg = HL7::Message::Segment::Default.new
segment_count = 0
seg.each do |_s|
segment_count += 1
end
expect(segment_count).to eq(seg.length)
end
end
describe "is_child_segment?" do
let(:segment) { HL7::Message::Segment.new "MSA|AR|ZZ9380 ERR" }
it "return false when is not set" do
expect(segment.is_child_segment?).to be false
end
end
describe "convert_to_ts" do
let(:time_now) { DateTime.now }
let(:formated_time) { time_now.strftime("%Y%m%d%H%M%S") }
it "convers to the hl7 time format" do
expect(HL7::Message::Segment.convert_to_ts(time_now)).to eq formated_time
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/batch_parsing_spec.rb | spec/batch_parsing_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message do
context "batch parsing" do
it "has a class method HL7::Message.parse_batch" do
expect(HL7::Message).to respond_to(:parse_batch)
end
it "raises an exception when parsing an empty batch" do
# :empty_batch message contains a valid batch envelope with no
# contents
expect do
HL7::Message.parse_batch HL7MESSAGES[:empty_batch]
end.to raise_exception(HL7::ParseError, "empty_batch_message")
end
it "raises an exception when parsing a single message as a batch" do
expect do
HL7::Message.parse_batch HL7MESSAGES[:realm_minimal_message]
end.to raise_exception(HL7::ParseError, "badly_formed_batch_message")
end
it "yields multiple messages from a valid batch" do
count = 0
HL7::Message.parse_batch(HL7MESSAGES[:realm_batch]) do |_m|
count += 1
end
expect(count).to eq 2
end
end
end
describe "String extension" do
before :all do
@batch_message = HL7MESSAGES[:realm_batch]
@plain_message = HL7MESSAGES[:realm_minimal_message]
end
it "respond_toes :hl7_batch?" do
expect(@batch_message.hl7_batch?).to be true
expect(@plain_message).to respond_to(:hl7_batch?)
end
it "returns true when passed a batch message" do
expect(@batch_message).to be_an_hl7_batch
end
it "returns false when passed a plain message" do
expect(@plain_message).not_to be_an_hl7_batch
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/rol_segment_spec.rb | spec/rol_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::ROL do
describe "segment parsing" do
let(:segment_string) do
"ROL|1|AD|Role|Role person|20240611|20240711|Duration|Role action reason|Provider type|Organization unit type|Office home address birthplace|Phone number|Person location|Organization"
end
let(:filled_rol) { HL7::Message::Segment::ROL.new(segment_string) }
it "allows access to a ROL segment's attributes" do
expect(filled_rol.role_instance).to eq("1")
expect(filled_rol.action_code).to eq("AD")
expect(filled_rol.role).to eq("Role")
expect(filled_rol.role_person).to eq("Role person")
expect(filled_rol.role_begin_date_time).to eq("20240611")
expect(filled_rol.role_end_date_time).to eq("20240711")
expect(filled_rol.role_duration).to eq("Duration")
expect(filled_rol.role_action_reason).to eq("Role action reason")
expect(filled_rol.provider_type).to eq("Provider type")
expect(filled_rol.organization_unit_type).to eq("Organization unit type")
expect(filled_rol.office_home_address_birthplace).to eq("Office home address birthplace")
expect(filled_rol.phone_number).to eq("Phone number")
expect(filled_rol.person_location).to eq("Person location")
expect(filled_rol.organization).to eq("Organization")
end
end
describe "segment creation" do
let(:rol) { HL7::Message::Segment::ROL.new }
let(:expected_segment_string) do
"ROL|1|AD|Role|Role person|20240611|20240711|Duration|Role action reason|Provider type|Organization unit type|Office home address birthplace|Phone number|Person location|Organization"
end
before do
rol.role_instance = "1"
rol.action_code = "AD"
rol.role = "Role"
rol.role_person = "Role person"
rol.role_begin_date_time = "20240611"
rol.role_end_date_time = "20240711"
rol.role_duration = "Duration"
rol.role_action_reason = "Role action reason"
rol.provider_type = "Provider type"
rol.organization_unit_type = "Organization unit type"
rol.office_home_address_birthplace = "Office home address birthplace"
rol.phone_number = "Phone number"
rol.person_location = "Person location"
rol.organization = "Organization"
end
it "serializes a ROL segment" do
expect(rol.to_s).to eq(expected_segment_string)
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/msh_segment_spec.rb | spec/msh_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::MSH do
context "general" do
before :all do
@base = "MSH|^~\\&||ABCHS||AUSDHSV|20070101112951||ADT^A04^ADT_A01|12334456778890|P|2.5|||NE|NE|AU|ASCII|ENGLISH|||AN ORG|||RECNET.ORG"
end
it "allows access to an MSH segment" do
msh = HL7::Message::Segment::MSH.new @base
msh.enc_chars = '^~\\&'
expect(msh.version_id).to eq "2.5"
expect(msh.country_code).to eq "AU"
expect(msh.charset).to eq "ASCII"
expect(msh.sending_responsible_org).to eq "AN ORG"
expect(msh.receiving_network_address).to eq "RECNET.ORG"
end
it "allows creation of an MSH segment" do
msh = HL7::Message::Segment::MSH.new
msh.sending_facility = "A Facility"
expect(msh.sending_facility).to eq "A Facility"
msh.time = DateTime.iso8601("20010203T040506")
expect(msh.time).to eq "20010203040506"
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/pv1_segment_spec.rb | spec/pv1_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::PV1 do
context "general" do
before :all do
@base = "PV1||R|||||||||||||||A|||V02^19900607~H02^19900607"
end
it "allows access to an PV1 segment" do
pv1 = HL7::Message::Segment::PV1.new @base
expect(pv1.patient_class).to eq "R"
end
it "allows creation of an OBX segment" do
pv1 = HL7::Message::Segment::PV1.new
pv1.referring_doctor = "Smith^John"
expect(pv1.referring_doctor).to eq "Smith^John"
pv1.admit_date = Date.new(2014, 1, 1)
expect(pv1.admit_date).to eq "20140101"
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/message_spec.rb | spec/message_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message do
describe "#correction?" do
subject { hl7.correction? }
let(:hl7) { HL7::Message.new data }
context "when is a correction" do
let(:data) do
[
"OBR|1|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300", # "F" final
"OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||F||||OMG",
"NTE|1||SOME",
"NTE|2||THOUGHTS",
"OBR|2|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300", # "C" corrected
"OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||C||||OMG",
"NTE|1||SOME",
"NTE|2||THOUGHTS",
].join("\r")
end
it { is_expected.to be true }
end
context "when is not a correction" do
let(:data) do
[
"OBR|1|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300", # "F" final
"OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||F||||OMG",
"NTE|1||SOME",
"NTE|2||THOUGHTS",
"OBR|2|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300", # "F" final
"OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||F||||OMG",
"NTE|1||SOME",
"NTE|2||THOUGHTS",
].join("\r")
end
it { is_expected.to be false }
end
context "when there are no results (OBX) segments" do
let(:data) do
[
"OBR|1|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300",
"OBR|2|A241Z^LAB||123456^A TEST^L|||201508181431||1234||||None|201502181432||||OMG123||||20150818143300",
].join("\r")
end
it { is_expected.to be false }
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/evn_segment_spec.rb | spec/evn_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::EVN do
context "general" do
before :all do
@base = "EVN|A04|20060705000000"
end
it "allows access to an EVN segment" do
evn = HL7::Message::Segment::EVN.new @base
expect(evn.type_code).to eq "A04"
end
it "allows creation of an EVN segment" do
evn = HL7::Message::Segment::EVN.new
evn.event_facility = "A Facility"
expect(evn.event_facility).to eq "A Facility"
evn.recorded_date = Date.new 2001, 2, 3
expect(evn.recorded_date).to eq "20010203"
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/obr_segment_spec.rb | spec/obr_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::OBR do
context "general" do
before :all do
@base = "OBR|2|^USSSA|0000000567^USSSA|37956^CT ABDOMEN^LN|||199405021550|||||||||||||0000763||||NMR|P||||||R/O TUMOR|202300&BAKER&MARK&E|||01&LOCHLEAR&JUDY|||||||||||||||123"
@obr = HL7::Message::Segment::OBR.new @base
end
it "allows access to an OBR segment" do
expect(@obr.to_s).to eq @base
expect(@obr.e1).to eq "2"
expect(@obr.set_id).to eq "2"
expect(@obr.placer_order_number).to eq "^USSSA"
expect(@obr.filler_order_number).to eq "0000000567^USSSA"
expect(@obr.universal_service_id).to eq "37956^CT ABDOMEN^LN"
end
it "allows modification of an OBR segment" do
@obr.set_id = 1
expect(@obr.set_id).to eq "1"
@obr.placer_order_number = "^DMCRES"
expect(@obr.placer_order_number).to eq "^DMCRES"
end
it "supports the diagnostic_serv_sect_id method" do
expect(@obr).to respond_to(:diagnostic_serv_sect_id)
expect(@obr.diagnostic_serv_sect_id).to eq "NMR"
end
it "supports the result_status method" do
expect(@obr).to respond_to(:result_status)
expect(@obr.result_status).to eq "P"
end
it "supports the reason_for_study method" do
expect(@obr.reason_for_study).to eq "R/O TUMOR"
end
it "supports the parent_universal_service_identifier method" do
expect(@obr.parent_universal_service_identifier).to eq "123"
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/nk1_segment_spec.rb | spec/nk1_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
# rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength
# reason: we need to assert every segment field to be exhaustive
describe HL7::Message::Segment::NK1 do
let(:segment_string) do
"NK1|1|Mum^Martha^M^^^^L|MTH^Mother^HL70063^^^^2.5.1|444 Home Street^Apt B^Ann Arbor^MI^99999^USA^H" \
"|5555552006|5555552007|EMC^Emergency Contact^HL70131|20011105|20011209|job_title|job_code|employee_number" \
"|organization_name|marital_status|F|20011209|living_dependency|ambulatory_status|citizenship" \
"|primary_language|living_arrangement|publicity_code|protection_indicator|student_indicator|religion" \
"|mother_maiden_name|nationality|ethnic_group|contact_reason|contact_persons_name|contact_persons_telephone_number" \
"|contact_persons_address|identifiers|job_status|race|handicap|contact_persons_ssn|birth_place|vip_indicator" \
"|telecommunication_information|contact_persons_telecommunication_information"
end
let(:filled_nk1) { HL7::Message::Segment::NK1.new(segment_string) }
describe "segment parsing" do
it "allows access to an NK1 segment's attributes" do
expect(filled_nk1.set_id).to eq "1"
expect(filled_nk1.name).to eq "Mum^Martha^M^^^^L"
expect(filled_nk1.relationship).to eq "MTH^Mother^HL70063^^^^2.5.1"
expect(filled_nk1.address).to eq "444 Home Street^Apt B^Ann Arbor^MI^99999^USA^H"
expect(filled_nk1.phone_number).to eq "5555552006"
expect(filled_nk1.business_phone_number).to eq "5555552007"
expect(filled_nk1.contact_role).to eq "EMC^Emergency Contact^HL70131"
expect(filled_nk1.start_date).to eq "20011105"
expect(filled_nk1.end_date).to eq "20011209"
expect(filled_nk1.job_title).to eq "job_title"
expect(filled_nk1.job_code).to eq "job_code"
expect(filled_nk1.employee_number).to eq "employee_number"
expect(filled_nk1.organization_name).to eq "organization_name"
expect(filled_nk1.marital_status).to eq "marital_status"
expect(filled_nk1.admin_sex).to eq "F"
expect(filled_nk1.date_of_birth).to eq "20011209"
expect(filled_nk1.living_dependency).to eq "living_dependency"
expect(filled_nk1.ambulatory_status).to eq "ambulatory_status"
expect(filled_nk1.citizenship).to eq "citizenship"
expect(filled_nk1.primary_language).to eq "primary_language"
expect(filled_nk1.living_arrangement).to eq "living_arrangement"
expect(filled_nk1.publicity_code).to eq "publicity_code"
expect(filled_nk1.protection_indicator).to eq "protection_indicator"
expect(filled_nk1.student_indicator).to eq "student_indicator"
expect(filled_nk1.religion).to eq "religion"
expect(filled_nk1.mother_maiden_name).to eq "mother_maiden_name"
expect(filled_nk1.nationality).to eq "nationality"
expect(filled_nk1.ethnic_group).to eq "ethnic_group"
expect(filled_nk1.contact_reason).to eq "contact_reason"
expect(filled_nk1.contact_persons_name).to eq "contact_persons_name"
expect(filled_nk1.contact_persons_telephone_number).to eq "contact_persons_telephone_number"
expect(filled_nk1.contact_persons_address).to eq "contact_persons_address"
expect(filled_nk1.identifiers).to eq "identifiers"
expect(filled_nk1.job_status).to eq "job_status"
expect(filled_nk1.race).to eq "race"
expect(filled_nk1.handicap).to eq "handicap"
expect(filled_nk1.contact_persons_ssn).to eq "contact_persons_ssn"
expect(filled_nk1.birth_place).to eq "birth_place"
expect(filled_nk1.vip_indicator).to eq "vip_indicator"
expect(filled_nk1.telecommunication_information).to eq "telecommunication_information"
expect(filled_nk1.contact_persons_telecommunication_information).to eq "contact_persons_telecommunication_information"
end
end
describe "segment creation" do
let(:nk1) { HL7::Message::Segment::NK1.new }
before do
nk1.set_id = "1"
nk1.name = "Mum^Martha^M^^^^L"
nk1.relationship = "MTH^Mother^HL70063^^^^2.5.1"
nk1.address = "444 Home Street^Apt B^Ann Arbor^MI^99999^USA^H"
nk1.phone_number = "5555552006"
nk1.business_phone_number = "5555552007"
nk1.contact_role = "EMC^Emergency Contact^HL70131"
nk1.start_date = "20011105"
nk1.end_date = "20011209"
nk1.job_title = "job_title"
nk1.job_code = "job_code"
nk1.employee_number = "employee_number"
nk1.organization_name = "organization_name"
nk1.marital_status = "marital_status"
nk1.admin_sex = "F"
nk1.date_of_birth = "20011209"
nk1.living_dependency = "living_dependency"
nk1.ambulatory_status = "ambulatory_status"
nk1.citizenship = "citizenship"
nk1.primary_language = "primary_language"
nk1.living_arrangement = "living_arrangement"
nk1.publicity_code = "publicity_code"
nk1.protection_indicator = "protection_indicator"
nk1.student_indicator = "student_indicator"
nk1.religion = "religion"
nk1.mother_maiden_name = "mother_maiden_name"
nk1.nationality = "nationality"
nk1.ethnic_group = "ethnic_group"
nk1.contact_reason = "contact_reason"
nk1.contact_persons_name = "contact_persons_name"
nk1.contact_persons_telephone_number = "contact_persons_telephone_number"
nk1.contact_persons_address = "contact_persons_address"
nk1.identifiers = "identifiers"
nk1.job_status = "job_status"
nk1.race = "race"
nk1.handicap = "handicap"
nk1.contact_persons_ssn = "contact_persons_ssn"
nk1.birth_place = "birth_place"
nk1.vip_indicator = "vip_indicator"
nk1.telecommunication_information = "telecommunication_information"
nk1.contact_persons_telecommunication_information = "contact_persons_telecommunication_information"
end
it "serializes an NK1 segment" do
expect(nk1.to_s).to eq(segment_string)
end
end
describe "#admin_sex=" do
context "when admin_sex is filled with an invalid value" do
it "raises an InvalidDataError" do
expect do
["TEST", "A", 1, 2].each do |x|
filled_nk1.admin_sex = x
end
end.to raise_error(HL7::InvalidDataError)
end
end
context "when admin_sex is filled with a valid value" do
it "does not raise any error" do
expect do
vals = %w[F M O U A N] + [nil]
vals.each do |x|
filled_nk1.admin_sex = x
end
filled_nk1.admin_sex = ""
end.not_to raise_error
end
end
end
end
# rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/aip_segment_spec.rb | spec/aip_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::AIP do
context "general" do
before :all do
@base_aip = "AIP|1|U|JSB^ISON^Kathy^S|D^Doctor||20020108150000|||10|m^Minutes"
end
it "creates an AIP segment" do
expect do
aip = HL7::Message::Segment::AIP.new(@base_aip)
expect(aip).not_to be_nil
expect(aip.to_s).to eq @base_aip
end.not_to raise_error
end
it "allows access to an AIP segment" do
expect do
aip = HL7::Message::Segment::AIP.new(@base_aip)
expect(aip.set_id).to eq "1"
expect(aip.segment_action_code).to eq "U"
expect(aip.personnel_resource_id).to eq "JSB^ISON^Kathy^S"
expect(aip.resource_role).to eq "D^Doctor"
expect(aip.start_date_time).to eq "20020108150000"
expect(aip.duration).to eq "10"
expect(aip.duration_units).to eq "m^Minutes"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/dg1_spec.rb | spec/dg1_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::DG1 do
context "reading" do
let(:base_string) do
"DG1|1|I9|71596^OSTEOARTHROS NOS-L/LEG ^I9|OSTEOARTHROS NOS-L/LEG |20170615140551-0800||A|"
end
let(:segment) { HL7::Message::Segment::DG1.new(base_string) }
it "allows access to an DG1 segment" do
expect(segment.set_id).to eq("1")
expect(segment.diagnosis_coding_method).to eq("I9")
expect(segment.diagnosis_code).to eq("71596^OSTEOARTHROS NOS-L/LEG ^I9")
expect(segment.diagnosis_description).to eq("OSTEOARTHROS NOS-L/LEG ")
expect(segment.diagnosis_date_time).to eq("20170615140551-0800")
expect(segment.diagnosis_type).to eq("")
expect(segment.major_diagnostic_category).to eq("A")
expect(segment.diagnosis_related_group).to eq("")
expect(segment.drg_approval_indicator).to be_nil
expect(segment.drg_grouper_review_code).to be_nil
expect(segment.outlier_type).to be_nil
expect(segment.outlier_days).to be_nil
expect(segment.outlier_cost).to be_nil
expect(segment.grouper_version_and_type).to be_nil
expect(segment.diagnosis_priority).to be_nil
expect(segment.diagnosis_clinician).to be_nil
expect(segment.diagnosis_classification).to be_nil
expect(segment.confidential_indicator).to be_nil
expect(segment.attestation_date_time).to be_nil
end
end
context "creating" do
let(:segment) { HL7::Message::Segment::DG1.new }
it "allows creation of an DGH segment" do
segment.set_id = "2"
expect(segment.set_id).to eq("2")
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/basic_parsing_spec.rb | spec/basic_parsing_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message do
context "basic parsing" do
before :all do
@simple_msh_txt = open("./test_data/test.hl7").readlines.first
@empty_txt = open("./test_data/empty.hl7").readlines.first
@empty_segments_txt = open("./test_data/empty_segments.hl7").readlines.first
@base_msh = "MSH|^~\\&|LAB1||DESTINATION||19910127105114||ORU^R03|LAB1003929"
@base_msh_alt_delims = "MSH$@~\\&|LAB1||DESTINATION||19910127105114||ORU^R03|LAB1003929"
end
it "parses simple text" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
expect(msg.to_hl7).to eq @simple_msh_txt
end
it "parses delimiters properly" do
msg = HL7::Message.new(@base_msh)
expect(msg.element_delim).to eq "|"
expect(msg.item_delim).to eq "^"
msg = HL7::Message.new(@base_msh_alt_delims)
expect(msg.element_delim).to eq "$"
expect(msg.item_delim).to eq "@"
end
it "parses via the constructor" do
msg = HL7::Message.new(@simple_msh_txt)
expect(msg.to_hl7).to eq @simple_msh_txt
end
it "parses via the class method" do
msg = HL7::Message.parse(@simple_msh_txt)
expect(msg.to_hl7).to eq @simple_msh_txt
end
it "only parses String and Enumerable data" do
expect { HL7::Message.parse :MSHthis_shouldnt_parse_at_all }.to raise_error(HL7::ParseError)
end
it "parses empty strings" do
expect { HL7::Message.new @empty_txt }.not_to raise_error
end
it "converts to strings" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
orig = @simple_msh_txt.tr("\r", "\n")
expect(msg.to_s).to eq orig
end
it "converts to a string and to HL7" do
msg = HL7::Message.new(@simple_msh_txt)
expect(msg.to_hl7).not_to eq(msg.to_s)
end
it "allows access to segments by index" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
expect(msg[0].to_s).to eq @base_msh
end
it "allows access to segments by name" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
expect(msg["MSH"].to_s).to eq @base_msh
end
it "allows access to segments by symbol" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
expect(msg[:MSH].to_s).to eq @base_msh
end
it "inserts segments by index" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
inp = HL7::Message::Segment::Default.new
msg[1] = inp
expect(msg[1]).to eq inp
expect { msg[2] = Class.new }.to raise_error(HL7::Exception)
end
it "returns nil when accessing a missing segment" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
expect { expect(msg[:does_not_exist]).to be_nil }.not_to raise_error
end
it "inserts segments by name" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
inp = HL7::Message::Segment::NTE.new
msg["NTE"] = inp
expect(msg["NTE"]).to eq inp
expect { msg["NTE"] = Class.new }.to raise_error(HL7::Exception)
end
it "inserts segments by symbol" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
inp = HL7::Message::Segment::NTE.new
msg[:NTE] = inp
expect(msg[:NTE]).to eq inp
expect { msg[:NTE] = Class.new }.to raise_error(HL7::Exception)
end
it "allows access to segment elements" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
expect(msg[:MSH].sending_app).to eq "LAB1"
end
it "allows modification of segment elements" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
msg[:MSH].sending_app = "TEST"
expect(msg[:MSH].sending_app).to eq "TEST"
end
it "raises NoMethodError when accessing a missing element" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
expect { msg[:MSH].does_not_really_exist_here }.to raise_error(NoMethodError)
end
it "raises NoMethodError when modifying a missing element" do
msg = HL7::Message.new
msg.parse @simple_msh_txt
expect { msg[:MSH].does_not_really_exist_here = "TEST" }.to raise_error(NoMethodError)
end
it "permits elements to be accessed via numeric names" do
msg = HL7::Message.new(@simple_msh_txt)
expect(msg[:MSH].e2).to eq "LAB1"
expect(msg[:MSH].e3).to be_empty
end
it "permits elements to be modified via numeric names" do
msg = HL7::Message.parse(@simple_msh_txt)
msg[:MSH].e2 = "TESTING1234"
expect(msg[:MSH].e2).to eq "TESTING1234"
end
it "allows appending of segments" do
msg = HL7::Message.new
expect do
msg << HL7::Message::Segment::MSH.new
msg << HL7::Message::Segment::NTE.new
end.not_to raise_error
expect { msg << Class.new }.to raise_error(HL7::Exception)
end
it "allows appending of an array of segments" do
msg = HL7::Message.new
expect do
msg << [HL7::Message::Segment::MSH.new, HL7::Message::Segment::NTE.new]
end.not_to raise_error
obx = HL7::Message::Segment::OBX.new
expect do
obx.children << [HL7::Message::Segment::NTE.new, HL7::Message::Segment::NTE.new]
end.not_to raise_error
end
it "sorts segments" do
msg = HL7::Message.new
pv1 = HL7::Message::Segment::PV1.new
msg << pv1
msh = HL7::Message::Segment::MSH.new
msg << msh
nte = HL7::Message::Segment::NTE.new
msg << nte
nte2 = HL7::Message::Segment::NTE.new
msg << nte2
msh.sending_app = "TEST"
initial = msg.to_s
sorted = msg.sort
final = sorted.to_s
expect(initial).not_to eq(final)
end
it "automatically assigns a set_id to a new segment" do
msg = HL7::Message.new
msh = HL7::Message::Segment::MSH.new
msg << msh
ntea = HL7::Message::Segment::NTE.new
ntea.comment = "first"
msg << ntea
nteb = HL7::Message::Segment::NTE.new
nteb.comment = "second"
msg << nteb
ntec = HL7::Message::Segment::NTE.new
ntec.comment = "third"
msg << ntec
expect(ntea.set_id).to eq "1"
expect(nteb.set_id).to eq "2"
expect(ntec.set_id).to eq "3"
end
it "parses Enumerable data" do
test_file = open("./test_data/test.hl7")
expect(test_file).not_to be_nil
msg = HL7::Message.new(test_file)
expect(msg.to_hl7).to eq @simple_msh_txt
end
it "has a to_info method" do
msg = HL7::Message.new(@simple_msh_txt)
expect(msg[1].to_info).not_to be_nil
end
it "parses a raw array" do
inp = "NTE|1|ME TOO"
nte = HL7::Message::Segment::NTE.new(inp.split("|"))
expect(nte.to_s).to eq inp
end
it "produces MLLP output" do
msg = HL7::Message.new(@simple_msh_txt)
expect = "\x0b%s\x1c\r" % msg.to_hl7
expect(msg.to_mllp).to eq expect
end
it "parses MLLP input" do
raw = format("\x0b%s\x1c\r", @simple_msh_txt)
msg = HL7::Message.parse(raw)
expect(msg).not_to be_nil
expect(msg.to_hl7).to eq @simple_msh_txt
expect(msg.to_mllp).to eq raw
end
it "can parse its own MLLP output" do
msg = HL7::Message.parse(@simple_msh_txt)
expect(msg).not_to be_nil
expect do
post_mllp = HL7::Message.parse(msg.to_mllp)
expect(post_mllp).not_to be_nil
expect(msg.to_hl7).to eq post_mllp.to_hl7
end.not_to raise_error
end
it "can access child elements" do
obr = HL7::Message::Segment::OBR.new
expect do
expect(obr.children).not_to be_nil
expect(obr.children.length).to be_zero
end.not_to raise_error
end
it "can add child elements" do
obr = HL7::Message::Segment::OBR.new
expect do
expect(obr.children.length).to be_zero
(1..5).each do |x|
obr.children << HL7::Message::Segment::OBX.new
expect(obr.children.length).to eq x
end
end.not_to raise_error
end
it "rejects invalid child segments" do
obr = HL7::Message::Segment::OBR.new
expect { obr.children << Class.new }.to raise_error(HL7::Exception)
end
it "supports grouped, sequenced segments" do
# multible obr's with multiple obx's
msg = HL7::Message.parse(@simple_msh_txt)
orig_output = msg.to_hl7
(1..10).each do |_obr_id|
obr = HL7::Message::Segment::OBR.new
msg << obr
(1..10).each do |_obx_id|
obx = HL7::Message::Segment::OBX.new
obr.children << obx
end
end
expect(msg[:OBR]).not_to be_nil
expect(msg[:OBR].length).to eq 11
expect(msg[:OBX]).not_to be_nil
expect(msg[:OBX].length).to eq 102
expect(msg[:OBR][4].children[1].set_id).to eq "2"
expect(msg[:OBR][5].children[1].set_id).to eq "2"
final_output = msg.to_hl7
expect(orig_output).not_to eq(final_output)
end
it "returns each segment's index" do
msg = HL7::Message.parse(@simple_msh_txt)
expect(msg.index("PID")).to eq 1
expect(msg.index(:PID)).to eq 1
expect(msg.index("PV1")).to eq 2
expect(msg.index(:PV1)).to eq 2
expect(msg.index("TACOBELL")).to be_nil
expect(msg.index(nil)).to be_nil
expect(msg.index(1)).to be_nil
end
it "validates the PID#admin_sex element" do
pid = HL7::Message::Segment::PID.new
expect { pid.admin_sex = "TEST" }.to raise_error(HL7::InvalidDataError)
expect { pid.admin_sex = "F" }.not_to raise_error
end
it "can parse an empty segment" do
expect { HL7::Message.new @empty_segments_txt }.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/err_segment_spec.rb | spec/err_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::ERR do
context "general" do
before :all do
@base_err = "ERR||OBR^1|100^Segment sequence error^HL70357|E|||Missing required OBR segment|Email help desk for further information on this error||||^NET^Internet^helpdesk@hl7.org"
end
it "creates an ERR segment" do
expect do
err = HL7::Message::Segment::ERR.new(@base_err)
expect(err).not_to be_nil
expect(err.to_s).to eq @base_err
end.not_to raise_error
end
it "allows access to an ERR segment" do
expect do
err = HL7::Message::Segment::ERR.new(@base_err)
expect(err.severity).to eq "E"
expect(err.error_location).to eq "OBR^1"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/mfe_segment_spec.rb | spec/mfe_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::MFE do
context "general" do
before :all do
@base_sft = "MFE|MAD|6772331|200106290500|BUD^Buddhist^HL70006|CE"
end
it "creates an MFE segment" do
expect do
sft = HL7::Message::Segment::MFE.new(@base_sft)
expect(sft).not_to be_nil
expect(sft.to_s).to eq(@base_sft)
end.not_to raise_error
end
it "allows access to an MFE segment" do
expect do
sft = HL7::Message::Segment::MFE.new(@base_sft)
expect(sft.record_level_event_code).to eq "MAD"
expect(sft.mfn_control_id).to eq "6772331"
expect(sft.primary_key_value).to eq "BUD^Buddhist^HL70006"
expect(sft.primary_key_value_type).to eq "CE"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/pid_segment_spec.rb | spec/pid_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::PID do
let(:segment) do
"PID|1||333||LastName^FirstName^MiddleInitial^SR^NickName||19760228|F||2106-3^White^HL70005^CAUC^Caucasian^L||AA||||||555.55|012345678||||||||||201011110924-0700|Y||UA|||||||"
end
let(:filled_pid) { HL7::Message::Segment::PID.new(segment) }
describe ".initialize" do
it "sets values correctly" do
expect(filled_pid.set_id).to eq "1"
expect(filled_pid.patient_id).to eq ""
expect(filled_pid.patient_id_list).to eq "333"
expect(filled_pid.alt_patient_id).to eq ""
expect(filled_pid.patient_name).to eq "LastName^FirstName^MiddleInitial^SR^NickName"
expect(filled_pid.mother_maiden_name).to eq ""
expect(filled_pid.patient_dob).to eq "19760228"
expect(filled_pid.admin_sex).to eq "F"
expect(filled_pid.patient_alias).to eq ""
expect(filled_pid.race).to eq "2106-3^White^HL70005^CAUC^Caucasian^L"
expect(filled_pid.address).to eq ""
expect(filled_pid.county_code).to eq "AA"
expect(filled_pid.phone_home).to eq ""
expect(filled_pid.phone_business).to eq ""
expect(filled_pid.primary_language).to eq ""
expect(filled_pid.marital_status).to eq ""
expect(filled_pid.religion).to eq ""
expect(filled_pid.account_number).to eq "555.55"
expect(filled_pid.social_security_num).to eq "012345678"
expect(filled_pid.driver_license_num).to eq ""
expect(filled_pid.mothers_id).to eq ""
expect(filled_pid.ethnic_group).to eq ""
expect(filled_pid.birthplace).to eq ""
expect(filled_pid.multi_birth).to eq ""
expect(filled_pid.birth_order).to eq ""
expect(filled_pid.citizenship).to eq ""
expect(filled_pid.vet_status).to eq ""
expect(filled_pid.nationality).to eq ""
expect(filled_pid.death_date).to eq "201011110924-0700"
expect(filled_pid.death_indicator).to eq "Y"
expect(filled_pid.id_unknown_indicator).to eq ""
expect(filled_pid.id_reliability_code).to eq "UA"
expect(filled_pid.last_update_date).to eq ""
expect(filled_pid.last_update_facility).to eq ""
expect(filled_pid.species_code).to eq ""
expect(filled_pid.breed_code).to eq ""
expect(filled_pid.strain).to eq ""
expect(filled_pid.production_class_code).to eq ""
expect(filled_pid.tribal_citizenship).to eq ""
end
end
describe "#country_code" do
it "aliases the county_code field as country_code for backward compatibility" do
expect(filled_pid.country_code).to eq "AA"
filled_pid.country_code = "ZZ"
expect(filled_pid.country_code).to eq "ZZ"
end
end
describe "#id_readability_code=" do
it "aliases the id_reliability_code field as id_readability_code for backward compatibility" do
expect(filled_pid.id_readability_code).to eq "UA"
filled_pid.id_readability_code = "AL"
expect(filled_pid.id_reliability_code).to eq "AL"
end
end
describe "#admin_sex=" do
context "when admin_sex is filled with an invalid value" do
it "raises an InvalidDataError" do
expect do
["TEST", "A", 1, 2].each do |x|
filled_pid.admin_sex = x
end
end.to raise_error(HL7::InvalidDataError)
end
end
context "when admin_sex is filled with a valid value" do
it "does not raise any error" do
expect do
vals = %w[F M O U A N] + [nil]
vals.each do |x|
filled_pid.admin_sex = x
end
filled_pid.admin_sex = ""
end.not_to raise_error
end
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/rf1_segment_spec.rb | spec/rf1_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::RF1 do
context "general" do
before :all do
@base = "RF1|P^Pending^HL70283|R^Routine^HL70280|GRF^General referral^HL70281|AM^Assume management^HL70282||8094|20060705||20060705||42"
end
it "allows access to an RF1 segment" do
rf1 = HL7::Message::Segment::RF1.new @base
expect(rf1.referral_status).to eq "P^Pending^HL70283"
expect(rf1.referral_priority).to eq "R^Routine^HL70280"
expect(rf1.referral_type).to eq "GRF^General referral^HL70281"
expect(rf1.referral_disposition).to eq "AM^Assume management^HL70282"
expect(rf1.originating_referral_identifier).to eq "8094"
expect(rf1.effective_date).to eq "20060705"
expect(rf1.process_date).to eq "20060705"
expect(rf1.external_referral_identifier).to eq "42"
end
it "allows creation of an RF1 segment" do
rf1 = HL7::Message::Segment::RF1.new
rf1.expiration_date = Date.new(2058, 12, 1)
expect(rf1.expiration_date).to eq "20581201"
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/in1_segment_spec.rb | spec/in1_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::IN1 do
context "general" do
before :all do
@base_in1 = "IN1|1||752|ACORDIA NATIONAL||||A|GRP|||||||SMITH^JOHN|19|19700102||||||||||||||||||WC23732763278A|||||||||||||||||X"
end
it "creates an IN1 segment" do
expect do
in1 = HL7::Message::Segment::IN1.new(@base_in1)
expect(in1).not_to be_nil
expect(in1.to_s).to eq @base_in1
end.not_to raise_error
end
it "allows access to an IN1 segment" do
expect do
in1 = HL7::Message::Segment::IN1.new(@base_in1)
expect(in1.set_id).to eq "1"
expect(in1.insurance_company_id).to eq "752"
expect(in1.insurance_company_name).to eq "ACORDIA NATIONAL"
expect(in1.group_number).to eq "A"
expect(in1.group_name).to eq "GRP"
expect(in1.name_of_insured).to eq "SMITH^JOHN"
expect(in1.insureds_relationship_to_patient).to eq "19"
expect(in1.insureds_date_of_birth).to eq "19700102"
expect(in1.policy_number).to eq "WC23732763278A"
expect(in1.vip_indicator).to eq "X"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/prt_segment_spec.rb | spec/prt_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::PRT do
describe "segment parsing" do
let(:segment_string) do
"PRT|1^N01^1^UUID|AD|Reason|AP|1^Author|Provider type|1|" \
"ORG^A||2^N01^2^UUID|20240611|20240711|Duration|" \
"2070 Test Park^^Los Angeles^CA^90067^USA^B^^06037|^ASN^CP"
end
let(:filled_prt) { HL7::Message::Segment::PRT.new(segment_string) }
it "allows access to a PRT segment's attributes" do
expect(filled_prt.participation_instance_id).to eq("1^N01^1^UUID")
expect(filled_prt.action_code).to eq("AD")
expect(filled_prt.action_reason).to eq("Reason")
expect(filled_prt.participation).to eq("AP")
expect(filled_prt.participation_person).to eq("1^Author")
expect(filled_prt.participation_person_provider_type).to eq("Provider type")
expect(filled_prt.participation_organization_unit_type).to eq("1")
expect(filled_prt.participation_organization).to eq("ORG^A")
expect(filled_prt.participation_location).to eq("")
expect(filled_prt.participation_device).to eq("2^N01^2^UUID")
expect(filled_prt.participation_begin_date_time).to eq("20240611")
expect(filled_prt.participation_end_date_time).to eq("20240711")
expect(filled_prt.participation_qualitative_duration).to eq("Duration")
expect(filled_prt.participation_address).to eq("2070 Test Park^^Los Angeles^CA^90067^USA^B^^06037")
expect(filled_prt.participation_telecommunication_address).to eq("^ASN^CP")
end
end
describe "segment creation" do
let(:prt) { HL7::Message::Segment::PRT.new }
let(:expected_segment_string) do
"PRT|1^N01^1^UUID|AD|Reason|AP|1^Author|Provider type|1|" \
"ORG^A||2^N01^2^UUID|20240611|20240711|Duration|" \
"2070 Test Park^^Los Angeles^CA^90067^USA^B^^06037|^ASN^CP"
end
before do
prt.participation_instance_id = "1^N01^1^UUID"
prt.action_code = "AD"
prt.action_reason = "Reason"
prt.participation = "AP"
prt.participation_person = "1^Author"
prt.participation_person_provider_type = "Provider type"
prt.participation_organization_unit_type = "1"
prt.participation_organization = "ORG^A"
prt.participation_location = ""
prt.participation_device = "2^N01^2^UUID"
prt.participation_begin_date_time = "20240611"
prt.participation_end_date_time = "20240711"
prt.participation_qualitative_duration = "Duration"
prt.participation_address = "2070 Test Park^^Los Angeles^CA^90067^USA^B^^06037"
prt.participation_telecommunication_address = "^ASN^CP"
end
it "serializes a PRT segment" do
expect(prt.to_s).to eq(expected_segment_string)
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/ft1_segment_spec.rb | spec/ft1_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::FT1 do
context "general" do
before :all do
@base_ft1 = "FT1|1|||20180705|20180705|||Description||1||||||123456^The Location|||R45.82^Worries~H18.892^Other specified disorders of cornea|1043312457^Provider^Testing^^^^|1043312457^Provider^Testing^^^^||||99392^HEART FAILURE COMPOSITE|"
end
it "creates an FT1 segment" do
expect do
ft1 = HL7::Message::Segment::FT1.new(@base_ft1)
expect(ft1).not_to be_nil
expect(ft1.to_s).to eq @base_ft1
end.not_to raise_error
end
it "allows access to an FT1 segment" do
expect do
ft1 = HL7::Message::Segment::FT1.new(@base_ft1)
expect(ft1.set_id).to eq "1"
expect(ft1.date_of_service).to eq "20180705"
expect(ft1.transaction_posting_date).to eq "20180705"
expect(ft1.transaction_description).to eq "Description"
expect(ft1.transaction_quantity).to eq "1"
expect(ft1.assigned_patient_location).to eq "123456^The Location"
expect(ft1.diagnosis_code).to eq "R45.82^Worries~H18.892^Other specified disorders of cornea"
expect(ft1.performed_by_provider).to eq "1043312457^Provider^Testing^^^^"
expect(ft1.ordering_provider).to eq "1043312457^Provider^Testing^^^^"
expect(ft1.procedure_code).to eq "99392^HEART FAILURE COMPOSITE"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/msa_segment_spec.rb | spec/msa_segment_spec.rb | # frozen_string_literal: true
$: << "../lib"
require "ruby-hl7"
describe HL7::Message::Segment::MSA do
context "general" do
before :all do
@base_msa = "MSA|AR|ZZ9380 ERR"
end
it "creates an MSA segment" do
expect do
msa = HL7::Message::Segment::MSA.new(@base_msa)
expect(msa).not_to be_nil
expect(msa.to_s).to eq @base_msa
end.not_to raise_error
end
it "allows access to an MSA segment" do
expect do
msa = HL7::Message::Segment::MSA.new(@base_msa)
expect(msa.ack_code).to eq "AR"
expect(msa.control_id).to eq "ZZ9380 ERR"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/fts_segment_spec.rb | spec/fts_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::FTS do
context "general" do
before :all do
base_string = "FTS||End of File"
@fts = HL7::Message::Segment::FTS.new(base_string)
end
it "creates an FTS segment" do
expect(@fts).not_to be_nil
end
it "allows access to an FTS segment" do
expect(@fts.file_batch_count).to eq("")
expect(@fts.file_trailer_comment).to eq("End of File")
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/txa_segment_spec.rb | spec/txa_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::TXA do
let(:segment) do
"TXA|1|AR|AP|20220611113300|1^Name|20220611|2022061110||1^Creator|" \
"1^Author|1^Typer|A^V02^UID^TC|A^V01^UID^TC|01|02|file.txt|C|P|AV|ST||" \
"2022061110|DC|AR|FileName|202206111011"
end
let(:filled_txa) { HL7::Message::Segment::TXA.new segment }
it "allows access to an TXA segment" do
expect(filled_txa.set_id).to eq("1")
expect(filled_txa.document_type).to eq("AR")
expect(filled_txa.document_content_presentation).to eq("AP")
expect(filled_txa.activity_date_time).to eq("20220611113300")
expect(filled_txa.primary_activity_provider_code).to eq("1^Name")
expect(filled_txa.origination_date_time).to eq("20220611")
expect(filled_txa.transcription_date_time).to eq("2022061110")
expect(filled_txa.edit_date_time).to eq("")
expect(filled_txa.originator_code).to eq("1^Creator")
expect(filled_txa.assigned_document_authenticator).to eq("1^Author")
expect(filled_txa.transcriptionist_code).to eq("1^Typer")
expect(filled_txa.unique_document_number).to eq("A^V02^UID^TC")
expect(filled_txa.parent_document_number).to eq("A^V01^UID^TC")
expect(filled_txa.placer_order_number).to eq("01")
expect(filled_txa.filler_order_number).to eq("02")
expect(filled_txa.unique_document_file_name).to eq("file.txt")
expect(filled_txa.document_completion_status).to eq("C")
expect(filled_txa.document_confidentiality_status).to eq("P")
expect(filled_txa.document_availability_status).to eq("AV")
expect(filled_txa.document_storage_status).to eq("ST")
expect(filled_txa.document_change_reason).to eq("")
expect(filled_txa.authentication_person_time_stamp).to eq("2022061110")
expect(filled_txa.distributed_copies_code).to eq("DC")
expect(filled_txa.folder_assignment).to eq("AR")
expect(filled_txa.document_title).to eq("FileName")
expect(filled_txa.agreed_due_date_time).to eq("202206111011")
end
it "allows creation of an TXA segment" do
txa = HL7::Message::Segment::TXA.new
txa.set_id = "1"
txa.document_type = "AR"
txa.document_content_presentation = "AP"
txa.activity_date_time = "20220611113300"
txa.primary_activity_provider_code = "1^Name"
txa.origination_date_time = "20220611"
txa.transcription_date_time = "2022061110"
txa.edit_date_time = ""
txa.originator_code = "1^Creator"
txa.assigned_document_authenticator = "1^Author"
txa.transcriptionist_code = "1^Typer"
txa.unique_document_number = "A^V02^UID^TC"
txa.parent_document_number = "A^V01^UID^TC"
txa.placer_order_number = "01"
txa.filler_order_number = "02"
txa.unique_document_file_name = "file.txt"
txa.document_completion_status = "C"
txa.document_confidentiality_status = "P"
txa.document_availability_status = "AV"
txa.document_storage_status = "ST"
txa.document_change_reason = ""
txa.authentication_person_time_stamp = "2022061110"
txa.distributed_copies_code = "DC"
txa.folder_assignment = "AR"
txa.document_title = "FileName"
txa.agreed_due_date_time = "202206111011"
expect(txa.to_s).to eq(segment)
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/mfi_segment_spec.rb | spec/mfi_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::MFI do
context "general" do
before :all do
@base_sft = "MFI|HL70006^RELIGION^HL70175|TEST|UPD|||AL"
end
it "creates an MFI segment" do
expect do
sft = described_class.new(@base_sft)
expect(sft).not_to be_nil
expect(sft.to_s).to eq(@base_sft)
end.not_to raise_error
end
it "allows access to an MFI segment" do
expect do
sft = described_class.new(@base_sft)
expect(sft.master_file_identifier).to eq "HL70006^RELIGION^HL70175"
expect(sft.master_file_application_identifier).to eq "TEST"
expect(sft.file_level_event_code).to eq "UPD"
expect(sft.response_level_code).to eq "AL"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/messages_spec.rb | spec/messages_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe "HL7 Messages" do
it "processes multiple known messages without failing" do
expect do
HL7MESSAGES.each_pair do |_key, hl7|
HL7::Message.new(hl7)
end
end.not_to raise_exception
end
describe "MFN M13 Messages" do
it "extracts the MSH" do
expect(HL7::Message.new(HL7MESSAGES[:mfn_m13])[:MSH].sending_app).to eq "HL7REG"
end
it "extracts the MFI" do
expect(HL7::Message.new(HL7MESSAGES[:mfn_m13])[:MFI].master_file_identifier).to eq "HL70006^RELIGION^HL70175"
end
it "extracts the MFE" do
expect(HL7::Message.new(HL7MESSAGES[:mfn_m13])[:MFE][0].mfn_control_id).to eq "6772333"
expect(HL7::Message.new(HL7MESSAGES[:mfn_m13])[:MFE][1].mfn_control_id).to eq "6772334"
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/obx_segment_spec.rb | spec/obx_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::OBX do
context "general" do
before :all do
@base = "OBX|1|NM|30341-2^Erythrocyte sedimentation rate^LN^815117^ESR^99USI^^^Erythrocyte sedimentation rate||10|mm/h^millimeter per hour^UCUM|0 to 17|N|0.1||F|||20110331140551-0800||Observer|||20110331150551-0800|^A Site|||Century Hospital^^^^^NIST-AA-1&2.16.840.1.113883.3.72.5.30.1&ISO^XX^^^987|2070 Test Park^^Los Angeles^CA^90067^USA^B^^06037|2343242^Knowsalot^Phil^J.^III^Dr.^^^NIST-AA-1&2.16.840.1.113883.3.72.5.30.1&ISO^L^^^DN"
end
it "allows access to an OBX segment" do
obx = HL7::Message::Segment::OBX.new @base
expect(obx.set_id).to eq "1"
expect(obx.value_type).to eq "NM"
expect(obx.observation_id).to eq "30341-2^Erythrocyte sedimentation rate^LN^815117^ESR^99USI^^^Erythrocyte sedimentation rate"
expect(obx.observation_sub_id).to eq ""
expect(obx.observation_value).to eq "10"
expect(obx.units).to eq "mm/h^millimeter per hour^UCUM"
expect(obx.references_range).to eq "0 to 17"
expect(obx.abnormal_flags).to eq "N"
expect(obx.probability).to eq "0.1"
expect(obx.nature_of_abnormal_test).to eq ""
expect(obx.observation_result_status).to eq "F"
expect(obx.effective_date_of_reference_range).to eq ""
expect(obx.user_defined_access_checks).to eq ""
expect(obx.observation_date).to eq "20110331140551-0800"
expect(obx.producer_id).to eq ""
expect(obx.responsible_observer).to eq "Observer"
expect(obx.observation_site).to eq "^A Site"
expect(obx.observation_method).to eq ""
expect(obx.equipment_instance_id).to eq ""
expect(obx.analysis_date).to eq "20110331150551-0800"
expect(obx.performing_organization_name).to eq "Century Hospital^^^^^NIST-AA-1&2.16.840.1.113883.3.72.5.30.1&ISO^XX^^^987"
expect(obx.performing_organization_address).to eq "2070 Test Park^^Los Angeles^CA^90067^USA^B^^06037"
expect(obx.performing_organization_medical_director).to eq "2343242^Knowsalot^Phil^J.^III^Dr.^^^NIST-AA-1&2.16.840.1.113883.3.72.5.30.1&ISO^L^^^DN"
end
it "allows creation of an OBX segment" do
expect do
obx = HL7::Message::Segment::OBX.new
obx.value_type = "TESTIES"
obx.observation_id = "HR"
obx.observation_sub_id = "2"
obx.observation_value = "SOMETHING HAPPENned"
end.not_to raise_error
end
describe "#correction?" do
subject { obx.correction? }
let(:obx) { HL7::Message::Segment::OBX.new data }
context "when is a correction" do
let(:data) do
"OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||C||||OMG"
end
it { is_expected.to be true }
end
context "when is not a correction" do
let(:data) do
"OBX|1|ST|123456^AA OBSERVATION^L^4567890^FIRST OBSERVATION^LN||42|ug/dL^Micrograms per Deciliter^UCUM|<10 ug/dL|H|||F||||OMG"
end
it { is_expected.to be false }
end
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/segment_list_storage_spec.rb | spec/segment_list_storage_spec.rb | # frozen_string_literal: true
require "spec_helper"
class SegmentNoChildren < HL7::Message::Segment
end
class SegmentWithChildren < HL7::Message::Segment
has_children %i[NTE ORC SPM]
end
describe HL7::Message::SegmentListStorage do
describe "self#add_child_type" do
it "allows to add a new segment type as child" do
SegmentWithChildren.add_child_type :OBR
segment = SegmentWithChildren.new
expect(segment.accepts?(:OBR)).to be true
expect(segment.child_types).to include :OBR
end
end
describe "Adding children has_children and add_child_type" do
subject do
segment_instance = segment_class.new
%i[accepts? child_types children].each do |method|
expect(segment_instance.respond_to?(method)).to be true
end
end
context "when child_types is not present" do
let(:segment_class) { SegmentNoChildren }
it "by adding add_child_type should respond to the children methods" do
segment_instance = segment_class.new
expect(segment_instance.respond_to?(:children)).to be false
segment_class.add_child_type(:OBR)
subject
end
end
context "when child_types is present" do
let(:segment_class) { SegmentWithChildren }
it "responds to the children methods" do
subject
end
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/gt1_segment_spec.rb | spec/gt1_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::GT1 do
context "general" do
before :all do
@base_gt1 = "GT1||440|Crusher^Beverly||1003 Elm Street^^Enterprise^MD^29433|(330)644-1234^^^bcrusher@ufp.net^^330^6441234| |19600411000000|F||18|339-33-6657||||||||F||||||||||M"
end
it "creates an GT1 segment" do
expect do
gt1 = HL7::Message::Segment::GT1.new(@base_gt1)
expect(gt1).not_to be_nil
expect(gt1.to_s).to eq @base_gt1
end.not_to raise_error
end
it "allows access to an GT1 segment" do
expect do
gt1 = HL7::Message::Segment::GT1.new(@base_gt1)
expect(gt1.guarantor_number).to eq "440"
expect(gt1.guarantor_name).to eq "Crusher^Beverly"
expect(gt1.guarantor_address).to eq "1003 Elm Street^^Enterprise^MD^29433"
expect(gt1.guarantor_date_of_birth).to eq "19600411000000"
expect(gt1.guarantor_sex).to eq "F"
expect(gt1.guarantor_relationship).to eq "18"
expect(gt1.guarantor_ssn).to eq "339-33-6657"
expect(gt1.guarantor_employment_status).to eq "F"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/prd_segment_spec.rb | spec/prd_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::PRD do
context "general" do
let(:base) do
"PRD|RP|LastName^FirstName^MiddleInitial^SR^NickName|444 Home Street^Apt B^Ann Arbor^MI^99999^USA|^^^A Wonderful Clinic|^WPN^PH^^^07^5555555|PH|4796^AUSHICPR|20130109163307+1000|20140109163307+1000"
end
let(:prd) { HL7::Message::Segment::PRD.new base }
it "sets the provider_role" do
expect(prd.provider_role).to eql "RP"
end
it "sets the name" do
expect(prd.provider_name).to eql "LastName^FirstName^MiddleInitial^SR^NickName"
end
it "sets the provider_address" do
expect(prd.provider_address).to eql "444 Home Street^Apt B^Ann Arbor^MI^99999^USA"
end
it "sets the provider_location" do
expect(prd.provider_location).to eql "^^^A Wonderful Clinic"
end
it "sets provider_communication_information" do
expect(prd.provider_communication_information).to eql "^WPN^PH^^^07^5555555"
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/segment_field_spec.rb | spec/segment_field_spec.rb | # frozen_string_literal: true
require "spec_helper"
class MockSegment < HL7::Message::Segment
weight 1
add_field :no_block
alias_field :no_block_alias, :no_block
add_field :validating do |value|
value == "bad" ? nil : value
end
add_field :converting do |value|
"X#{value}"
end
end
describe HL7::Message::Segment do
before :all do
@base = "Mock|no_block|validated|converted"
end
context "block on field definitions" do
it "is evaluated on access by field name" do
msg = MockSegment.new(@base)
expect(msg.to_s).to eq @base
expect(msg.no_block).to eq "no_block"
expect(msg.validating).to eq "validated"
expect(msg.converting).to eq "Xconverted"
msg.no_block = "NO_BLOCK"
expect(msg.no_block).to eq "NO_BLOCK"
msg.validating = "good"
expect(msg.validating).to eq "good"
msg.validating = "bad"
expect(msg.validating).to eq ""
msg.converting = "empty"
expect(msg.converting).to eq "XXempty"
end
it "is not evaluated on read access by eXXX alias" do
msg = MockSegment.new(@base)
expect(msg.e1).to eq "no_block"
expect(msg.e2).to eq "validated"
expect(msg.e3).to eq "converted"
end
it "is not evaluated on write access by eXXX alias" do
msg = MockSegment.new(@base)
msg.e1 = "NO_BLOCK"
expect(msg.e1).to eq "NO_BLOCK"
msg.e2 = "good"
expect(msg.e2).to eq "good"
msg.e2 = "bad"
expect(msg.e2).to eq "bad"
msg.e3 = "empty"
expect(msg.e3).to eq "empty"
end
end
describe "#[]" do
it "allows index access to the segment" do
msg = HL7::Message::Segment.new(@base)
expect(msg[0]).to eq "Mock"
expect(msg[1]).to eq "no_block"
expect(msg[2]).to eq "validated"
expect(msg[3]).to eq "converted"
end
end
describe "#[]=" do
it "allows index assignment to the segment" do
msg = HL7::Message::Segment.new(@base)
msg[0] = "Kcom"
expect(msg[0]).to eq "Kcom"
end
end
describe "#alias_field" do
context "with a valid field" do
it "uses alias field names" do
msg = MockSegment.new(@base)
expect(msg.no_block).to eq "no_block"
expect(msg.no_block_alias).to eq "no_block"
end
end
context "with an invalid field" do
class MockInvalidSegment < HL7::Message::Segment
weight 1
add_field :no_block
alias_field :no_block_alias, :invalid_field
add_field :second
add_field :third
end
it "throws an error when the field is invalid" do
msg = MockInvalidSegment.new(@base)
expect { msg.no_block_alias }.to raise_error(HL7::InvalidDataError)
end
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/ail_segment_spec.rb | spec/ail_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::AIL do
context "general" do
before :all do
@base_ail = "AIL|1|A|OFFICE^^^OFFICE|^OFFICE^A4"
end
it "creates an AIL segment" do
expect do
ail = HL7::Message::Segment::AIL.new(@base_ail)
expect(ail).not_to be_nil
expect(ail.to_s).to eq @base_ail
end.not_to raise_error
end
it "allows access to an AIL segment" do
expect do
ail = HL7::Message::Segment::AIL.new(@base_ail)
expect(ail.set_id).to eq "1"
expect(ail.segment_action_code).to eq "A"
expect(ail.location_resource_id).to eq "OFFICE^^^OFFICE"
expect(ail.location_type).to eq "^OFFICE^A4"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/speed_parsing_spec.rb | spec/speed_parsing_spec.rb | # frozen_string_literal: true
require "spec_helper"
require "time"
describe HL7::Message do
context "speed parsing" do
before :all do
@msg = open("./test_data/lotsunknowns.hl7").readlines
end
it "parses large, unknown segments rapidly" do
start = Time.now
doc = HL7::Message.new @msg
expect(doc).not_to be_nil
ends = Time.now
expect(ends - start).to be < 1
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/sch_segment_spec.rb | spec/sch_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::SCH do
context "general" do
before :all do
@base_sch = "SCH|||||681|S^SCHEDULED|^BONE DENSITY PB,cf/RH |30^30 MINUTE APPOINTMENT|45|m|^^45^200905260930^200905261015|||||||||polly^^POLLY BRESCOCK|^^^^^^ ||||SCHEDULED"
end
it "creates an SCH segment" do
expect do
sch = HL7::Message::Segment::SCH.new(@base_sch)
expect(sch).not_to be_nil
expect(sch.to_s).to eq @base_sch
end.not_to raise_error
end
it "allows access to an SCH segment" do
expect do
sch = HL7::Message::Segment::SCH.new(@base_sch)
expect(sch.schedule_id).to eq "681"
expect(sch.event_reason).to eq "S^SCHEDULED"
expect(sch.appointment_reason).to eq "^BONE DENSITY PB,cf/RH "
expect(sch.appointment_type).to eq "30^30 MINUTE APPOINTMENT"
expect(sch.appointment_duration).to eq "45"
expect(sch.appointment_duration_units).to eq "m"
expect(sch.entered_by_person).to eq "polly^^POLLY BRESCOCK"
expect(sch.filler_status_code).to eq "SCHEDULED"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/default_segment_spec.rb | spec/default_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::Default do
context "general" do
before :all do
@base_msa = "MSA|AR|ZZ9380 ERR"
end
it "stores an existing segment" do
seg = HL7::Message::Segment::Default.new(@base_msa)
expect(seg.to_s).to eq @base_msa
end
it "converts to a string" do
seg = HL7::Message::Segment::Default.new(@base_msa)
expect(seg.to_s).to eq @base_msa
expect(seg.to_hl7).to eq seg.to_s
end
it "creates a raw segment" do
seg = HL7::Message::Segment::Default.new
seg.e0 = "NK1"
seg.e1 = "INFO"
seg.e2 = "MORE INFO"
seg.e5 = "LAST INFO"
expect(seg.to_s).to eq "NK1|INFO|MORE INFO|||LAST INFO"
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/spec_helper.rb | spec/spec_helper.rb | # frozen_string_literal: true
require "simplecov"
if ENV["COVERAGE"]
SimpleCov.start do
add_filter "/test/"
add_filter "/spec/"
end
end
# ruby-hl7 loads the rest of the files in lib
require File.expand_path("../lib/ruby-hl7", __dir__)
require File.expand_path("../lib/test/hl7_messages", __dir__)
RSpec.configure do |config|
config.include TimeFormatterHelper, :type => :helper
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/pv2_segment_spec.rb | spec/pv2_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
# rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength
# reason: we need to assert every segment field to be exhaustive
describe HL7::Message::Segment::PV2 do
let(:filled_pv2) { HL7::Message::Segment::PV2.new(segment_string) }
let(:segment_string) do
"PV2|prior_pending_location|accommodation_code|admit_reason|transfer_reason|patient_valuables" \
"|patient_valuables_location|visit_user_code|expected_admit_date|expected_discharge_date" \
"|estimated_length_of_inpatient_stay|actual_length_of_inpatient_stay|visit_description|referral_source_code" \
"|previous_service_date|employment_illness_related_indicator|purge_status_code|purge_status_date" \
"|special_program_code|retention_indicator|expected_number_of_insurance_plans|visit_publicity_code" \
"|visit_protection_indicator|clinic_organization_name|patient_status_code|visit_priority_code" \
"|previous_treatment_date|expected_discharge_disposition|signature_on_file" \
"|first_similar_illness_date|patient_charge_adjustment_code|recurring_service_code|billing_media_code" \
"|expected_surgery_date|military_partnership_code|military_non_availability_code|newborn_baby_indicator" \
"|baby_detained_indicator|mode_of_arrival_code|recreational_drug_use_code|admission_level_of_care_code" \
"|precaution_code|patient_condition_code|living_will_code|organ_donor_code|advance_directive_code" \
"|patient_status_effective_date|expected_loa_return_date|expected_preadmission_testing_date" \
"|notify_clergy_code"
end
describe "segment parsing" do
it "allows access to a PV2 segment's attributes" do
expect(filled_pv2.prior_pending_location).to eq("prior_pending_location")
expect(filled_pv2.accommodation_code).to eq("accommodation_code")
expect(filled_pv2.admit_reason).to eq("admit_reason")
expect(filled_pv2.transfer_reason).to eq("transfer_reason")
expect(filled_pv2.patient_valuables).to eq("patient_valuables")
expect(filled_pv2.patient_valuables_location).to eq("patient_valuables_location")
expect(filled_pv2.visit_user_code).to eq("visit_user_code")
expect(filled_pv2.expected_admit_date).to eq("expected_admit_date")
expect(filled_pv2.expected_discharge_date).to eq("expected_discharge_date")
expect(filled_pv2.estimated_inpatient_stay_length).to eq("estimated_length_of_inpatient_stay")
expect(filled_pv2.actual_inpatient_stay_length).to eq("actual_length_of_inpatient_stay")
expect(filled_pv2.visit_description).to eq("visit_description")
expect(filled_pv2.referral_source_code).to eq("referral_source_code")
expect(filled_pv2.previous_service_date).to eq("previous_service_date")
expect(filled_pv2.employment_illness_related_indicator).to eq("employment_illness_related_indicator")
expect(filled_pv2.purge_status_code).to eq("purge_status_code")
expect(filled_pv2.purge_status_date).to eq("purge_status_date")
expect(filled_pv2.special_program_code).to eq("special_program_code")
expect(filled_pv2.retention_indicator).to eq("retention_indicator")
expect(filled_pv2.expected_number_of_insurance_plans).to eq("expected_number_of_insurance_plans")
expect(filled_pv2.visit_publicity_code).to eq("visit_publicity_code")
expect(filled_pv2.visit_protection_indicator).to eq("visit_protection_indicator")
expect(filled_pv2.clinic_organization_name).to eq("clinic_organization_name")
expect(filled_pv2.patient_status_code).to eq("patient_status_code")
expect(filled_pv2.visit_priority_code).to eq("visit_priority_code")
expect(filled_pv2.previous_treatment_date).to eq("previous_treatment_date")
expect(filled_pv2.expected_discharge_disposition).to eq("expected_discharge_disposition")
expect(filled_pv2.signature_on_file).to eq("signature_on_file")
expect(filled_pv2.first_similar_illness_date).to eq("first_similar_illness_date")
expect(filled_pv2.patient_charge_adjustment_code).to eq("patient_charge_adjustment_code")
expect(filled_pv2.recurring_service_code).to eq("recurring_service_code")
expect(filled_pv2.billing_media_code).to eq("billing_media_code")
expect(filled_pv2.expected_surgery_date).to eq("expected_surgery_date")
expect(filled_pv2.military_partnership_code).to eq("military_partnership_code")
expect(filled_pv2.military_non_availability_code).to eq("military_non_availability_code")
expect(filled_pv2.newborn_baby_indicator).to eq("newborn_baby_indicator")
expect(filled_pv2.baby_detained_indicator).to eq("baby_detained_indicator")
expect(filled_pv2.mode_of_arrival_code).to eq("mode_of_arrival_code")
expect(filled_pv2.recreational_drug_use_code).to eq("recreational_drug_use_code")
expect(filled_pv2.admission_level_of_care_code).to eq("admission_level_of_care_code")
expect(filled_pv2.precaution_code).to eq("precaution_code")
expect(filled_pv2.patient_condition_code).to eq("patient_condition_code")
expect(filled_pv2.living_will_code).to eq("living_will_code")
expect(filled_pv2.organ_donor_code).to eq("organ_donor_code")
expect(filled_pv2.advance_directive_code).to eq("advance_directive_code")
expect(filled_pv2.patient_status_effective_date).to eq("patient_status_effective_date")
expect(filled_pv2.expected_loa_return_date).to eq("expected_loa_return_date")
expect(filled_pv2.expected_preadmission_testing_date).to eq("expected_preadmission_testing_date")
expect(filled_pv2.notify_clergy_code).to eq("notify_clergy_code")
end
end
describe "segment creation" do
let(:pv2) { HL7::Message::Segment::PV2.new }
let(:expected_segment_string) do
"PV2|prior_pending_location|accommodation_code|admit_reason|transfer_reason|patient_valuables" \
"|patient_valuables_location|visit_user_code|expected_admit_date|expected_discharge_date" \
"|estimated_length_of_inpatient_stay|actual_length_of_inpatient_stay|visit_description|referral_source_code" \
"|previous_service_date|employment_illness_related_indicator|purge_status_code|purge_status_date" \
"|special_program_code|retention_indicator|expected_number_of_insurance_plans|visit_publicity_code" \
"|visit_protection_indicator|clinic_organization_name|patient_status_code|visit_priority_code" \
"|previous_treatment_date|expected_discharge_disposition|signature_on_file" \
"|first_similar_illness_date|patient_charge_adjustment_code|recurring_service_code|billing_media_code" \
"|expected_surgery_date|military_partnership_code|military_non_availability_code|newborn_baby_indicator" \
"|baby_detained_indicator|mode_of_arrival_code|recreational_drug_use_code|admission_level_of_care_code" \
"|precaution_code|patient_condition_code|living_will_code|organ_donor_code|advance_directive_code" \
"|patient_status_effective_date|expected_loa_return_date|expected_preadmission_testing_date" \
"|notify_clergy_code"
end
before do
pv2.prior_pending_location = "prior_pending_location"
pv2.accommodation_code = "accommodation_code"
pv2.admit_reason = "admit_reason"
pv2.transfer_reason = "transfer_reason"
pv2.patient_valuables = "patient_valuables"
pv2.patient_valuables_location = "patient_valuables_location"
pv2.visit_user_code = "visit_user_code"
pv2.expected_admit_date = "expected_admit_date"
pv2.expected_discharge_date = "expected_discharge_date"
pv2.estimated_inpatient_stay_length = "estimated_length_of_inpatient_stay"
pv2.actual_inpatient_stay_length = "actual_length_of_inpatient_stay"
pv2.visit_description = "visit_description"
pv2.referral_source_code = "referral_source_code"
pv2.previous_service_date = "previous_service_date"
pv2.employment_illness_related_indicator = "employment_illness_related_indicator"
pv2.purge_status_code = "purge_status_code"
pv2.purge_status_date = "purge_status_date"
pv2.special_program_code = "special_program_code"
pv2.retention_indicator = "retention_indicator"
pv2.expected_number_of_insurance_plans = "expected_number_of_insurance_plans"
pv2.visit_publicity_code = "visit_publicity_code"
pv2.visit_protection_indicator = "visit_protection_indicator"
pv2.clinic_organization_name = "clinic_organization_name"
pv2.patient_status_code = "patient_status_code"
pv2.visit_priority_code = "visit_priority_code"
pv2.previous_treatment_date = "previous_treatment_date"
pv2.expected_discharge_disposition = "expected_discharge_disposition"
pv2.signature_on_file = "signature_on_file"
pv2.first_similar_illness_date = "first_similar_illness_date"
pv2.patient_charge_adjustment_code = "patient_charge_adjustment_code"
pv2.recurring_service_code = "recurring_service_code"
pv2.billing_media_code = "billing_media_code"
pv2.expected_surgery_date = "expected_surgery_date"
pv2.military_partnership_code = "military_partnership_code"
pv2.military_non_availability_code = "military_non_availability_code"
pv2.newborn_baby_indicator = "newborn_baby_indicator"
pv2.baby_detained_indicator = "baby_detained_indicator"
pv2.mode_of_arrival_code = "mode_of_arrival_code"
pv2.recreational_drug_use_code = "recreational_drug_use_code"
pv2.admission_level_of_care_code = "admission_level_of_care_code"
pv2.precaution_code = "precaution_code"
pv2.patient_condition_code = "patient_condition_code"
pv2.living_will_code = "living_will_code"
pv2.organ_donor_code = "organ_donor_code"
pv2.advance_directive_code = "advance_directive_code"
pv2.patient_status_effective_date = "patient_status_effective_date"
pv2.expected_loa_return_date = "expected_loa_return_date"
pv2.expected_preadmission_testing_date = "expected_preadmission_testing_date"
pv2.notify_clergy_code = "notify_clergy_code"
end
it "serializes a PV2 segment" do
expect(pv2.to_s).to eq(expected_segment_string)
end
end
describe "military_non_availibility_code" do
it "aliases the military_non_availability_code field as military_non_availibility_code for backward compatibility" do
expect(filled_pv2.military_non_availibility_code).to eq "military_non_availability_code"
filled_pv2.military_non_availibility_code = "test"
expect(filled_pv2.military_non_availibility_code).to eq "test"
end
end
end
# rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/segment_generator_spec.rb | spec/segment_generator_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::SegmentGenerator do
describe "valid_segments_parts?" do
let(:element) { "MSH|1|2|3" }
let(:delimiter) { HL7::Message::Delimiter.new("|", "^", '\r') }
let(:segment_generator) do
HL7::Message::SegmentGenerator.new(element, nil, delimiter)
end
it "returns true if @seg_parts is an array of one element or more" do
expect(segment_generator.valid_segments_parts?).to be true
end
context "when is empty" do
it "returns false if empty_segment_is_error is false" do
segment_generator.seg_parts = nil
HL7.configuration.empty_segment_is_error = false
expect(segment_generator.valid_segments_parts?).to be false
end
it "raises an error if empty_segment_is_error is true" do
HL7.configuration.empty_segment_is_error = true
segment_generator.seg_parts = nil
expect do
segment_generator.valid_segments_parts?
end.to raise_error HL7::EmptySegmentNotAllowed
end
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/spm_segment_spec.rb | spec/spm_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message::Segment::SPM do
context "general" do
before :all do
@base_spm = "SPM|1|23456&EHR&2.16.840.1.113883.19.3.2.3&ISO^9700122&Lab&2.16.840.1.113883.19.3.1.6&ISO||122554006^Capillary blood specimen^SCT^BLDC^Blood capillary^HL70070^20080131^2.5.1||HEPA^Ammonium heparin^HL70371^^^^2.5.1|CAP^Capillary Specimen^HL70488^^^^2.5.1|181395001^Venous structure of digit^SCT^^^^20080731|||P^Patient^HL60369^^^^2.5.1|50^uL&Micro Liter&UCUM&&&&1.6|||||200808151030-0700|200808151100-0700"
end
it "creates an SPM segment" do
expect do
spm = HL7::Message::Segment::SPM.new(@base_spm)
expect(spm).not_to be_nil
expect(spm.to_s).to eq @base_spm
end.not_to raise_error
end
it "allows access to an SPM segment" do
expect do
spm = HL7::Message::Segment::SPM.new(@base_spm)
expect(spm.specimen_type).to eq "122554006^Capillary blood specimen^SCT^BLDC^Blood capillary^HL70070^20080131^2.5.1"
expect(spm.set_id).to eq "1"
end.not_to raise_error
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/orc_segment_spec.rb | spec/orc_segment_spec.rb | # frozen_string_literal: true
$: << "../lib"
require "ruby-hl7"
describe HL7::Message::Segment::ORC do
context "general" do
before :all do
@base_orc = "ORC|RE|23456^EHR^2.16.840.1.113883.19.3.2.3^ISO|9700123^Lab^2.16.840.1.113883.19.3.1.6^ISO|||||||||1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD||^WPN^PH^^1^555^5551005|||||||Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234|1005 Healthcare Drive^^Ann Arbor^MI^99999^USA^B|^WPN^PH^^1^555^5553001|4444 Healthcare Drive^Suite 123^Ann Arbor^MI^99999^USA^B|||||||7844"
end
it "creates an ORC segment" do
expect do
orc = HL7::Message::Segment::ORC.new(@base_orc)
expect(orc).not_to be_nil
expect(orc.to_s).to eq @base_orc
end.not_to raise_error
end
it "allows access to an ORC segment" do
orc = HL7::Message::Segment::ORC.new(@base_orc)
expect(orc.ordering_provider).to eq "1234^Admit^Alan^A^III^Dr^^^&2.16.840.1.113883.19.4.6^ISO^L^^^EI^&2.16.840.1.113883.19.4.6^ISO^^^^^^^^MD"
expect(orc.call_back_phone_number).to eq "^WPN^PH^^1^555^5551005"
expect(orc.ordering_facility_name).to eq "Level Seven Healthcare, Inc.^L^^^^&2.16.840.1.113883.19.4.6^ISO^XX^^^1234"
expect(orc.parent_universal_service_identifier).to eq "7844"
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/child_segment_spec.rb | spec/child_segment_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe HL7::Message do
context "child segments" do
before :all do
@base = open("./test_data/obxobr.hl7").readlines
end
it "allows access to child segments" do
msg = HL7::Message.new @base
expect(msg).not_to be_nil
expect(msg[:OBR]).not_to be_nil
expect(msg[:OBR].length).to eq 3
expect(msg[:OBR][0].children).not_to be_nil
expect(msg[:OBR][0].children.length).to eq 6
expect(msg[:OBR][1].children).not_to be_nil
expect(msg[:OBR][1].children.length).to eq 3
expect(msg[:OBR][2].children).not_to be_nil
expect(msg[:OBR][2].children.length).to eq 1
expect(msg[:OBX][0].children).not_to be_nil
expect(msg[:OBX][0].children.length).to eq 1
msg[:OBR][0].children.each do |x|
expect(x).not_to be_nil
end
msg[:OBR][1].children.each do |x|
expect(x).not_to be_nil
end
msg[:OBR][2].children.each do |x|
expect(x).not_to be_nil
end
end
it "allows adding child segments" do
msg = HL7::Message.new @base
expect(msg).not_to be_nil
expect(msg[:OBR]).not_to be_nil
ob = HL7::Message::Segment::OBR.new
expect(ob).not_to be_nil
msg << ob
expect(ob.children).not_to be_nil
expect(ob.segment_parent).not_to be_nil
expect(ob.segment_parent).to eq msg
orig_cnt = msg.length
(1..4).each do |x|
m = HL7::Message::Segment::OBX.new
m.observation_value = "taco"
expect(m).not_to be_nil
expect(/taco/.match(m.to_s)).not_to be_nil
ob.children << m
expect(ob.children.length).to eq x
expect(m.segment_parent).not_to be_nil
expect(m.segment_parent).to eq ob
end
expect(@base).not_to eq msg.to_hl7
expect(msg.length).not_to eq orig_cnt
text_ver = msg.to_hl7
expect(/taco/.match(text_ver)).not_to be_nil
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/helpers/time_formatter_helper_spec.rb | spec/helpers/time_formatter_helper_spec.rb | # frozen_string_literal: true
require "spec_helper"
RSpec.describe TimeFormatterHelper, :type => :helper do
describe "#hl7_formatted_timestamp" do
subject(:formatted_date) { hl7_formatted_timestamp(value, fraction_digits) }
let(:fraction_digits) { 0 }
context "when value is not a Time nor a DateTime" do
let(:value) { Date.today }
it "raises a ValueTypeNotSupportedError" do
expect { formatted_date }.to raise_error(TimeFormatterHelper::ValueTypeNotSupportedError)
end
end
context "when value is a Time" do
let(:value) { Time.now }
context "when fraction_digits is 0 (default value)" do
it "returns the expected formatted string" do
expect(formatted_date).to eq(value.strftime("%Y%m%d%H%M%S"))
end
end
context "when fraction_digits is given" do
let(:fraction_digits) { 9 }
let(:fraction9) { ".#{format("%06d", value.to_time.usec)}#{"0" * 3}" }
it "returns the expected formatted string" do
expect(formatted_date).to eq(value.strftime("%Y%m%d%H%M%S") + fraction9)
end
end
end
context "when value is a DateTime" do
let(:value) { DateTime.now }
context "when fraction_digits is 0 (default value)" do
it "returns the expected formatted string" do
expect(formatted_date).to eq(value.strftime("%Y%m%d%H%M%S"))
end
end
context "when fraction_digits is given" do
let(:fraction_digits) { 3 }
let(:fraction3) { ".#{format("%06d", value.to_time.usec)[0, 3]}" }
it "returns the expected formatted string" do
expect(formatted_date).to eq(value.strftime("%Y%m%d%H%M%S") + fraction3)
end
end
end
end
describe "#hl7_formatted_date" do
subject(:formatted_date) { hl7_formatted_date(value) }
context "when value is not a Date" do
let(:value) { Time.new }
it "raises a ValueTypeNotSupportedError" do
expect { formatted_date }.to raise_error(TimeFormatterHelper::ValueTypeNotSupportedError)
end
end
context "when value is a Date" do
let(:value) { Date.today }
it "returns the expected formatted string" do
expect(formatted_date).to eq(value.strftime("%Y%m%d"))
end
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/spec/core_ext/date_time_spec.rb | spec/core_ext/date_time_spec.rb | # frozen_string_literal: true
require "spec_helper"
describe Date do
subject { Date.parse("2013-12-02").to_hl7 }
it "responds to the HL7 timestamp" do
expect(subject).to eq "20131202"
end
end
describe "to_hl7 for time related classes" do
let(:formated_time) { time_now.strftime("%Y%m%d%H%M%S") }
let(:fraction_3) { ".#{format("%06d", time_now.to_time.usec)[0, 3]}" }
let(:fraction_9) { ".#{format("%06d", time_now.to_time.usec)}#{"0" * 3}" }
shared_examples "a time to_hl7" do
context "without fraction" do
it { expect(time_now.to_time.to_hl7).to eq formated_time }
end
context "with_fraction" do
it { expect(time_now.to_time.to_hl7(3)).to eq formated_time + fraction_3 }
it { expect(time_now.to_time.to_hl7(9)).to eq formated_time + fraction_9 }
end
end
describe Time do
let(:time_now) { Time.now }
it_behaves_like "a time to_hl7"
end
describe DateTime do
let(:time_now) { DateTime.now }
it_behaves_like "a time to_hl7"
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/examples/proxy_server.rb | examples/proxy_server.rb | # frozen_string_literal: true
# $Id$
# Ruby-HL7 Proxy Server Example
require "rubygems"
require "ruby-hl7"
require "socket"
PORT = 2402
target_ip = "127.0.0.1"
target_port = 5900
srv = TCPServer.new(PORT)
puts format("proxy_server listening on port: %i", PORT)
puts format("proxying for: %s:%i", target_ip, target_port)
loop do
sok = srv.accept
Thread.new(sok) do |my_socket|
my_socket.readlines
msg = HL7::Message.new(raw_input)
puts format("forwarding message:\n%s", msg.to_s)
soc = TCPSocket.open(target_ip, target_port)
soc.write msg.to_mllp
soc.close
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/version.rb | lib/version.rb | # frozen_string_literal: true
module RubyHl7
VERSION = "1.4.0"
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segment_list_storage.rb | lib/segment_list_storage.rb | # frozen_string_literal: true
# This module includes methods for storing segments inside segments.
# has_children(child_types) defines three methods dynamically.
module HL7::Message::SegmentListStorage
attr_reader :child_types
def add_child_type(child_type)
if defined?(@child_types)
@child_types << child_type.to_sym
else
has_children [child_type.to_sym]
end
end
private
# allows a segment to store other segment objects
# used to handle associated lists like one OBR to many OBX segments
def has_children(child_types)
@child_types = child_types
define_method_child_types
define_method_children
define_method_accepts
end
def define_method_child_types
define_method(:child_types) do
self.class.child_types
end
end
def define_method_accepts
class_eval do
define_method(:accepts?) do |t|
t = t.to_sym if t.respond_to?(:to_sym)
!!child_types.index(t)
end
end
end
def define_method_children
class_eval do
define_method(:children) do
unless defined?(@my_children)
p = self
@my_children ||= []
@my_children.instance_eval do
@parental = p
alias :old_append :<<
def <<(value)
# do nothing if value is nil
return unless value
# make sure it's an array
value = [value].flatten
value.map {|item| append(item) }
end
def append(value)
unless value.is_a?(HL7::Message::Segment)
raise HL7::Exception, "attempting to append non-segment to a segment list"
end
value.segment_parent = @parental
k = @parental
k = k.segment_parent while k&.segment_parent && !k.segment_parent.is_a?(HL7::Message)
k.segment_parent << value if k&.segment_parent
old_append(value)
end
end
end
@my_children
end
end
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/message_parser.rb | lib/message_parser.rb | # frozen_string_literal: true
module HL7::MessageBatchParser
def parse_batch(batch) # :yields: message
raise HL7::ParseError, "badly_formed_batch_message" unless
batch.hl7_batch?
batch = clean_batch_for_jruby batch
raise HL7::ParseError, "empty_batch_message" unless
match = /\rMSH/.match(batch)
match.post_match.split("\rMSH").each do |_msg|
if md = /\rBTS/.match(_msg)
# TODO: Validate the message count in the BTS segment
# should == index + 1
_msg = md.pre_match
end
yield "MSH#{_msg}"
end
end
# parse a String or Enumerable object into an HL7::Message if possible
# * returns a new HL7::Message if successful
def parse(inobj)
HL7::Message.new do |msg|
msg.parse(inobj)
end
end
# JRuby seems to change our literal \r characters in sample
# messages (from here documents) into newlines. We make a copy
# here, reverting to carriage returns. The input is unchanged.
#
# This does not occur when posts are received with CR
# characters, only in sample messages from here documents. The
# expensive copy is only incurred when the batch message has a
# newline character in it.
private
def clean_batch_for_jruby(batch)
batch.tr("\n", "\r") if batch.include?("\n")
end
end
# Provides basic methods to parse_string, element and item delimeter parser
class HL7::MessageParser
attr_reader :delimiter
def self.split_by_delimiter(element, delimiter)
element.split(delimiter, -1)
end
def initialize(delimiter)
@delimiter = delimiter
end
# parse the provided String or Enumerable object into this message
def parse_string(instr)
post_mllp = instr
if /\x0b((:?.|\r|\n)+)\x1c\r/ =~ instr
post_mllp = $1 # strip the mllp bytes
end
HL7::MessageParser.split_by_delimiter(post_mllp, @delimiter.segment)
end
# Get the element delimiter from an MSH segment
def parse_element_delim(str)
str.is_a?(String) ? str.slice(3, 1) : "|"
end
# Get the item delimiter from an MSH segment
def parse_item_delim(str)
str.is_a?(String) ? str.slice(4, 1) : "^"
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
ruby-hl7/ruby-hl7 | https://github.com/ruby-hl7/ruby-hl7/blob/d5c8ee0288d225591c611a8474da5c520e5415f6/lib/segment_fields.rb | lib/segment_fields.rb | # frozen_string_literal: true
# SegmentFields
# class HL7::Message::Segment::NK1 < HL7::Message::Segment
# weight 100 # segments are sorted ascendingly
# add_field :something_you_want # assumes :idx=>1
# add_field :something_else, :idx=>6 # :idx=>6 and field count=6
module HL7::Message::SegmentFields
def self.included(base)
base.extend(ClassMethods)
end
@elements = []
module ClassMethods
# define a field alias
# * name is the alias itself (required)
# * options is a hash of parameters
# * :id is the field number to reference (optional, auto-increments from 1
# by default)
# * :blk is a validation proc (optional, overrides the second argument)
# * blk is an optional validation/convertion proc which MUST
# take a parameter and always return a value for the field (it will be
# used on read/write calls)
def add_field(name, options = {}, &blk)
options = { :idx => -1, :blk => blk }.merge!(options)
name ||= :id
namesym = name.to_sym
@field_cnt ||= 1
if options[:idx] == -1
options[:idx] = @field_cnt # provide default auto-incrementing
end
@field_cnt = options[:idx].to_i + 1
singleton.module_eval do
@fields ||= {}
@fields[namesym] = options
end
class_eval <<-END, __FILE__, __LINE__ + 1
def #{name}(val=nil)
unless val
read_field( :#{namesym} )
else
write_field( :#{namesym}, val )
val # this matches existing n= method functionality
end
end
def #{name}=(value)
write_field( :#{namesym}, value )
end
END
end
def fields # :nodoc:
singleton.module_eval do
(@fields ||= [])
end
end
def alias_field(new_field_name, old_field_name)
class_eval <<-END, __FILE__, __LINE__ + 1
def #{new_field_name}(val=nil)
raise HL7::InvalidDataError.new unless self.class.fields[:#{old_field_name}]
unless val
read_field( :#{old_field_name} )
else
write_field( :#{old_field_name}, val )
val # this matches existing n= method functionality
end
end
def #{new_field_name}=(value)
write_field( :#{old_field_name}, value )
end
END
end
end
def field_info(name) # :nodoc:
field_blk = nil
idx = name # assume we've gotten a integer
unless name.is_a?(Integer)
fld_info = self.class.fields[name]
idx = fld_info[:idx].to_i
field_blk = fld_info[:blk]
end
[idx, field_blk]
end
def [](index)
@elements[index]
end
def []=(index, value)
@elements[index] = value.to_s
end
def read_field(name) # :nodoc:
idx, field_blk = field_info(name)
return nil unless idx
return nil if idx >= @elements.length
ret = @elements[idx]
ret = ret.first if ret.is_a?(Array) && ret.length == 1
ret = field_blk.call(ret) if field_blk
ret
end
def write_field(name, value) # :nodoc:
idx, field_blk = field_info(name)
return nil unless idx
if idx >= @elements.length
# make some space for the incoming field, missing items are assumed to
# be empty, so this is valid per the spec -mg
missing = ("," * (idx - @elements.length)).split(",", -1)
@elements += missing
end
value = value.first if value.is_a?(Array) && value.length == 1
value = field_blk.call(value) if field_blk
@elements[idx] = value.to_s
end
end
| ruby | MIT | d5c8ee0288d225591c611a8474da5c520e5415f6 | 2026-01-04T17:51:14.403379Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.