spec/ios/nsattributedstring_spec.rb in sugarcube-2.11.0 vs spec/ios/nsattributedstring_spec.rb in sugarcube-2.11.1

- old
+ new

@@ -2,107 +2,88 @@ describe 'NSString attribute string methods' do it 'should have #bold' do subject = 'test'.bold - subject.should.be.kind_of(NSAttributedString) - subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSFont' => :bold.uifont} + subject.should.have_string_attributes({NSFontAttributeName => :bold.uifont}) end it 'should have #italic' do subject = 'test'.italic - subject.should.be.kind_of(NSAttributedString) - subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSFont' => :italic.uifont} + subject.should.have_string_attributes({NSFontAttributeName => :italic.uifont}) end it 'should have #monospace' do subject = 'test'.monospace - subject.should.be.kind_of(NSAttributedString) - subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSFont' => :monospace.uifont} + subject.should.have_string_attributes({NSFontAttributeName => :monospace.uifont}) end it 'should have #underline' do subject = 'test'.underline - subject.should.be.kind_of(NSAttributedString) - subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSUnderline' => NSUnderlineStyleSingle} + subject.should.have_string_attributes({NSUnderlineStyleAttributeName => NSUnderlineStyleSingle}) end it 'should be chainable' do subject = 'test'.bold.underline - subject.should.be.kind_of(NSAttributedString) - subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSFont' => :bold.uifont, 'NSUnderline' => NSUnderlineStyleSingle} + subject.should.have_string_attributes({NSFontAttributeName => :bold.uifont, NSUnderlineStyleAttributeName => NSUnderlineStyleSingle}) end end describe "should support all attribute names" do before do @subject = 'test'.attrd end - it "should be sane" do - @subject.isEqualToAttributedString('test'.attrd).should == true + it 'should have `paragraph_style`' do + par_style = NSMutableParagraphStyle.alloc.init + par_style.alignment = NSTextAlignmentRight + 'test'.attrd.paragraph_style(par_style).should.have_string_attributes({ NSParagraphStyleAttributeName => par_style }) end it 'should have `font`' do - @subject.isEqualToAttributedString('test'.attrd.font(:bold.uifont)).should != true - @subject.isEqualToAttributedString('test'.attrd.font('Helvetica')).should != true + 'test'.attrd.font(:bold.uifont).should.have_string_attributes({ NSFontAttributeName => :bold.uifont }) + 'test'.attrd.font('Helvetica').should.have_string_attributes({ NSFontAttributeName => 'Helvetica'.uifont }) end - it 'should have `paragraph_style`' do - @subject.isEqualToAttributedString('test'.attrd.paragraph_style(NSMutableParagraphStyle.alloc.init.tap{|s| s.alignment = UITextAlignmentRight })).should != true - end - it 'should have `foreground_color`' do - @subject.isEqualToAttributedString('test'.attrd.foreground_color(UIColor.redColor)).should != true - @subject.isEqualToAttributedString('test'.attrd.color(UIColor.redColor)).should != true + 'test'.attrd.foreground_color(UIColor.redColor).should.have_string_attributes({ NSForegroundColorAttributeName => UIColor.redColor }) + 'test'.attrd.color(UIColor.redColor).should.have_string_attributes({ NSForegroundColorAttributeName => UIColor.redColor }) end - it 'should have `underline_style`' do - @subject.isEqualToAttributedString('test'.attrd.underline_style(NSUnderlineStyleSingle)).should != true - end - it 'should have `background_color`' do - @subject.isEqualToAttributedString('test'.attrd.background_color(UIColor.redColor)).should != true - @subject.isEqualToAttributedString('test'.attrd.bg_color(UIColor.redColor)).should != true + 'test'.attrd.background_color(UIColor.redColor).should.have_string_attributes({ NSBackgroundColorAttributeName => UIColor.redColor }) + 'test'.attrd.bg_color(UIColor.redColor).should.have_string_attributes({ NSBackgroundColorAttributeName => UIColor.redColor }) end - # don't care about: - # it 'should have `attachment`' do - # @subject.isEqualToAttributedString('test'.attrd.attachment()).should != true - # end - - it 'should have `ligature`' do - @subject.isEqualToAttributedString('test'.attrd.ligature(2)).should != true + it 'should have `stroke_color`' do + 'test'.attrd.stroke_color(UIColor.redColor).should.have_string_attributes({ NSStrokeColorAttributeName => UIColor.redColor }) end - it 'should have `kern`' do - @subject.isEqualToAttributedString('test'.attrd.kern(1)).should != true + it 'should have `underline_style`' do + subject = 'test'.attrd.underline_style(NSUnderlineStyleSingle) + subject.should.have_string_attributes({NSUnderlineStyleAttributeName => NSUnderlineStyleSingle}) end - it 'should have `stroke_width`' do - @subject.isEqualToAttributedString('test'.attrd.stroke_width(1)).should != true + it 'should have `underline_style`' do + subject = 'test'.attrd.underline + subject.should.have_string_attributes({NSUnderlineStyleAttributeName => NSUnderlineStyleSingle}) end - it 'should have `stroke_color`' do - @subject.isEqualToAttributedString('test'.attrd.stroke_color(UIColor.redColor)).should != true + it 'should have `superscript`' do + subject = 'test'.attrd.superscript + subject.should.have_string_attributes({KCTSuperscriptAttributeName => 1}) + subject = 'test'.attrd.superscript(2) + subject.should.have_string_attributes({KCTSuperscriptAttributeName => 2}) end - it 'should have `strikethrough_style`' do - @subject.isEqualToAttributedString('test'.attrd.strikethrough_style(NSUnderlineStyleSingle)).should != true + it 'should have `subscript`' do + subject = 'test'.attrd.subscript + subject.should.have_string_attributes({KCTSuperscriptAttributeName => -1}) end - it 'should have `shadow`' do - @subject.isEqualToAttributedString('test'.attrd.shadow(NSShadow.alloc.init.tap{|s|s.shadowOffset = [1,1]})).should != true - end - - it 'should have `vertical_glyph_form`' do - @subject.isEqualToAttributedString('test'.attrd.vertical_glyph_form(1)).should != true - end - it 'should have `letterpress`' do - @subject.isEqualToAttributedString('test'.attrd.letterpress).should != true + 'test'.attrd.letterpress.should.have_string_attributes({ NSTextEffectAttributeName => NSTextEffectLetterpressStyle }) end - end end