processings_helper_spec.rb
2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'rails_helper'
describe ProcessingsHelper, :type => :helper do
describe 'humanize_eplased_time' do
it 'should convert it to readable words' do
expect(helper.humanize_eplased_time(6)).to eq('less than a minute')
end
end
describe 'format_grade' do
it 'should format a Float to a readable format' do
expect(helper.format_grade(1.333333333)).to eq("1.33")
end
end
describe 'find_range_snapshot' do
let(:metric_configuration_snapshot) { FactoryGirl.build(:metric_configuration_snapshot)}
let(:metric_result) { FactoryGirl.build(:metric_result, {value: 6.0, configuration: metric_configuration_snapshot})}
let(:range_snapshot_1_to_5) { FactoryGirl.build(:range_snapshot, {beginning: 1.0, end: 5.0}) }
let(:range_snapshot_5dot1_to_10) { FactoryGirl.build(:range_snapshot, {beginning: 5.1, end: 10.0}) }
let(:range_snapshot_10dot1_to_15) { FactoryGirl.build(:range_snapshot, {beginning: 10.1, end: 15.0}) }
before :each do
metric_configuration_snapshot.expects(:range_snapshot).
returns([range_snapshot_1_to_5,
range_snapshot_5dot1_to_10,
range_snapshot_10dot1_to_15])
end
it 'should return the range snapshot in which the value was in between' do
expect(helper.find_range_snapshot(metric_result)).to eq(range_snapshot_5dot1_to_10)
end
end
describe 'format_module_name' do
context 'when it is a String' do
let(:name) { 'org' }
it 'should not make any change' do
expect(helper.format_module_name(name)).to eq(name)
end
end
context 'when it is a Array' do
let(:name) { ['org', 'mezuro'] }
it "should return it's last element" do
expect(helper.format_module_name(name)).to eq(name.last)
end
end
context 'when it is a neither Array or String' do
let(:name) { Object.new }
it "should try to convert it to String" do
name.expects(:to_s)
helper.format_module_name(name)
end
end
end
end