Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I use RSpec but in a way I would use any xUnit framework. Can this snippet be refactored to look more BDD like (using subject and stuff)?

describe Time do
  describe ".from_sql" do
    it "parses date from Vertica" do
      actual = Time.from_sql "2012-10-17 12:34:56"
      expected = Time.new 2012, 10, 17, 12, 34, 56, 0
      actual.should == expected
    end
  end

  describe "#to_js_date" do
    it "is converted to JS format" do
      t = Time.new 2012, 11, 20
      t.to_js_date.should == "2012/11/20"
    end
  end
end
share|improve this question
add comment

1 Answer 1

describe Time do
  describe ".from_sql" do
    context "parsing from Vertica" do
      subject { Time.from_sql "2012-10-17 12:34:56" }

      it { should == Time.new(2012, 10, 17, 12, 34, 56, 0) }
    end
  end

  describe "#to_js_date" do
    subject { Time.new(2012, 11, 20).to_js_date }

    it { should == "2012/11/20" }

    # OR
    # subject { Time.new(2012, 11, 20) }
    #
    # its(:to_js_date) { should == "2012/11/20" }
  end
end
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.