spec/voting_builder/elements/span_spec.rb in neutral-0.0.2 vs spec/voting_builder/elements/span_spec.rb in neutral-0.0.3
- old
+ new
@@ -5,14 +5,15 @@
describe Span, type: :feature do
[Span::Positive, Span::Negative].each do |span|
describe span do
describe "#to_s" do
let(:total) { rand(100) + 1 }
+ let(:klass) { span.to_s.demodulize.downcase }
subject { Capybara.string span.new(total).to_s }
- it { should have_selector("span##{span.to_s.demodulize.downcase}") }
+ it { should have_selector("span.#{klass}") }
it "has value of given total" do
subject.find("span").text.should == total.to_s
end
@@ -22,23 +23,27 @@
end
end
end
describe Span::Difference do
+ def difference_element(total)
+ Capybara.string(Span::Difference.new(total).to_s).find("span")
+ end
+
describe "#to_s" do
let(:positive) { rand(100) + 1 }
let(:negative) { -(rand(100) + 1) }
it "has absolute value of total" do
- Capybara.string(Span::Difference.new(negative).to_s).find("span").text.to_i.should > 0
+ difference_element(negative).text.to_i.should > 0
end
it "has 'positive' class when positive value of total is passed" do
- Capybara.string(Span::Difference.new(positive).to_s).find("span")[:class].should == "positive"
+ difference_element(positive)[:class].should include("positive")
end
it "has 'negative' class when negative value of total is passed" do
- Capybara.string(Span::Difference.new(negative).to_s).find("span")[:class].should == "negative"
+ difference_element(negative)[:class].should include("negative")
end
end
end
end