Skip to content

Commit

Permalink
Added calculation service helper test
Browse files Browse the repository at this point in the history
  • Loading branch information
olexandervanzuriak committed Nov 27, 2024
1 parent 8a0a37f commit 3bf95ba
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions spec/helpers/calculators/calculation_service_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Calculators::CalculationService, type: :helper do
let(:calculator) { instance_double("Calculator", formulas: formulas) }
let(:formulas) do
[
instance_double("Formula", expression: "x + y", en_label: "Addition", en_unit: "units", uk_label: "Додавання", uk_unit: "одиниці"),
instance_double("Formula", expression: "x * y", en_label: "Multiplication", en_unit: "units", uk_label: "Множення", uk_unit: "одиниці")
]
end
let(:inputs) { ActionController::Parameters.new({ x: 5, y: 3 }) }

before do
allow_any_instance_of(ApplicationHelper).to receive(:current_locale?).with(:en).and_return(locale_en)
end

describe "#perform" do
subject { described_class.new(calculator, inputs).perform }

context "when locale is English" do
let(:locale_en) { true }

it "returns results with English labels and units" do
expect(subject).to eq([
{ label: "Addition", result: 8, en_unit: "units" },
{ label: "Multiplication", result: 15, en_unit: "units" }
])
end
end

context "when locale is Ukrainian" do
let(:locale_en) { false }

it "returns results with Ukrainian labels and units" do
expect(subject).to eq([
{ label: "Додавання", result: 8, en_unit: "одиниці" },
{ label: "Множення", result: 15, en_unit: "одиниці" }
])
end
end
end
end

0 comments on commit 3bf95ba

Please sign in to comment.