随笔分类 -  Ruby

Ruby Jruby
摘要:引用链接:http://reverocean.iteye.com/blog/14899571. describe和context describe和context方法用来组织相关的行为example。使用一个字符串作为他们的参数,以及使用一个block来定义其上下文的范围。写model的spec或者其他的unit test时,可以传一个Ruby类作为describe的第一个参数。Doing so also creates an implicit subject for the examples.describe Timesheet do ……enddescribe可以嵌套一般使用:descri 阅读全文
posted @ 2013-08-16 14:23 dami.van 阅读(1139) 评论(0) 推荐(0)
摘要:1.安装NppExec 插件2.按快捷键F6,在弹出框中输入如下命令:npp_save cd "$(CURRENT_DIRECTORY)" jruby "$(FILE_NAME)" 3.save保存命令后,点击点击ok开始执行 阅读全文
posted @ 2013-08-14 18:23 dami.van 阅读(435) 评论(0) 推荐(0)
摘要:引用链接:http://cukes.info/step-definitions.htmlData TablesData Tables are handy for specifying a larger piece of data:Given the following users exist: | name | email | phone | | Aslak | aslak@email.com | 123 | | Matt | matt@email.com | 234 | | Joe | joe@email.org | 456 | Just... 阅读全文
posted @ 2013-08-07 17:08 dami.van 阅读(4171) 评论(0) 推荐(0)
摘要:引用链接:https://github.com/cucumber/cucumber/wiki/Scenario-Outlinesscript/cucumber--i18nzh-CN|feature|"功能"||background|"背景"||scenario|"场景"||scenario_outline|"场景大纲"||examples|"例子"||given|"*","假如"||when|"*","当"||the 阅读全文
posted @ 2013-08-07 17:07 dami.van 阅读(1161) 评论(0) 推荐(0)
摘要:引用链接:http://watirmelon.com/2011/01/24/composition-or-inheritance-for-delegating-page-methods/Composition or inheritance for delegating pagemethods?Posted on January 24, 2011The thing I like to do when creating a page object pattern for automated web testing is delegating any methods that don’t belon 阅读全文
posted @ 2013-08-06 16:02 dami.van 阅读(253) 评论(0) 推荐(0)
摘要:在cucumber的自动化测试框架下面,在一个steps文件中定义的@page对象,可以在其他的不同的steps文件中调用,在整个的场景生命周期中都是有效的原因:cucumber开始执行时,一次性把所有的steps文件都加入到了内存中,所以...会出现这种现象 阅读全文
posted @ 2013-08-05 16:06 dami.van 阅读(273) 评论(2) 推荐(0)
摘要:#定义一个UTF-8=>GBK的方法def encoding inStr Iconv.iconv("GBK","UTF-8",inStr)end#定义一个GBK=>UTF-8的方法def unencoding inStr Iconv.iconv("UTF-8","GBK",inStr).joinend学习参考:http://www.kuqin.com/rubycndocument/man/addlib/Iconv.html#Iconv.2eiconvIconv 类类方法Iconv.new(to, fro 阅读全文
posted @ 2013-07-31 10:59 dami.van 阅读(1375) 评论(0) 推荐(0)
摘要:引用链接:http://www.blogjava.net/nkjava/archive/2010/01/03/308088.html1,切片:silce, [ ]-----------------[ ]是silce的别名,所以两者是完全相同的操作1:判定字符串中是否含有字串/子模式string[substring]string[/pattern/]string[/pattern/, position] #position之后的子串中是否含有/pattern/如果存在返回子串/子模式串,否则返回nil“hello world"["hello"]==="he 阅读全文
posted @ 2013-07-30 19:52 dami.van 阅读(6195) 评论(0) 推荐(0)
摘要:最常见的方式就是使用内置的get 方法,这个方法可以从命令行读取用户的输入,并在默认的情况下把读入的文本赋值给预定义变量$_.但是get方法会保留用户在输入字符串末尾所加的换行符,当用户在输入的字符串结尾输入了句号,并按了回车,得到的是stop\n。ruby中提供了另外一个内置的方法chomp,它会除去$_后面的换行符。 print "please enter anything:" gets chomp puts "The input is #{$_}" 用户的输入可以赋值给一个变量并来替换$_,但是删除末尾的空行就有问题,因为chmop只能对$_操作, 阅读全文
posted @ 2013-07-30 18:00 dami.van 阅读(410) 评论(0) 推荐(0)
摘要:1.load( io )Load a document from the current io stream.File.open( 'animals.yaml' ) { |yf| YAML::load( yf ) } #=> ['badger', 'elephant', 'tiger']example:require 'yaml'yml = YAML::load(File.open('t.yml'))p yml Can also load from a string.YAML.load( &q 阅读全文
posted @ 2013-07-29 12:22 dami.van 阅读(1497) 评论(0) 推荐(0)
摘要:1.sort → new_ary click to toggle sourcesort { |a, b| block } → new_aryReturns a new array created by sorting self.Comparisons for the sort will be done using the operator or using an optional code block.The block must implement a comparison between a and b, and return -1, when a follows b, 0 when a. 阅读全文
posted @ 2013-07-29 12:18 dami.van 阅读(9997) 评论(0) 推荐(0)
摘要:由[索引, 值, ...] 型的数组变为哈希表ary = [1,"a", 2,"b", 3,"c"]p Hash[*ary]# => {1=>"a", 2=>"b", 3=>"c"}由索引和值配对出现的数组变为哈希表alist = [[1,"a"], [2,"b"], [3,"c"]]p Hash[*alist.flatten]#=> {1=>"a", 2=&g 阅读全文
posted @ 2013-07-29 10:00 dami.van 阅读(1516) 评论(0) 推荐(0)
摘要:http://rubydoc.info/gems/watir-webdriver/frameshttp://rdoc.info/gems/watir-webdriver/frameshttp://www.ruby-doc.org/core-2.0/Array.html 阅读全文
posted @ 2013-07-27 01:16 dami.van 阅读(207) 评论(0) 推荐(0)
摘要:原文链接:http://www.ruby-doc.org/core-1.9.3/Regexp.htmlRegexpA Regexp holds a regular expression, used to match a pattern against strings. Regexps are created using the /.../ and %r{...} literals, and by the Regexp::new constructor.Regular expressions (regexps) are patterns which describe the contents o 阅读全文
posted @ 2013-07-25 23:48 dami.van 阅读(466) 评论(0) 推荐(0)
摘要:1.puts /[一-龥]+/.match("this is 中文") =>中文2.str2="123中文"puts /\p{Han}+/u.match(str2)文本编码格式:utf-8文件第一行:#encoding:utf-8require "rubygems"require "iconv"print Iconv.iconv("GBK","UTF-8",/\p{Han}+/u.match("tiantianxin你好angshang天天向上")[ 阅读全文
posted @ 2013-07-25 23:47 dami.van 阅读(1639) 评论(0) 推荐(0)
摘要:假设一个字符串当中有很多符合规则的信息,下面的例子可以把所有匹配到的结果打印出来:message="afhadhffkdf414j9tr3j43i3433094jwoert223jwew123dfdf"regex=/[a-z](\d{3})[a-z]/ message.scan(regex).each{|m|puts"Test#{m[0]}"} message="afhadhffkdf414j9tr3j43i3433094jwoert223jwew123dfdf"regex=/[a-z](\d{3})[a-z]/ message.sc 阅读全文
posted @ 2013-07-25 23:32 dami.van 阅读(1093) 评论(0) 推荐(0)
摘要:1.在线的ruby正则表达式编辑工具:http://www.rubular.com/2.Ruby的正则表达式以"//"作为构造方法。表达式返回一个RegExp的对象puts /a/.class =>Regexp3.String和RegExp均支持=~和match 2个查询匹配方法puts "hello world!"=~/llo/ => 2a=/llo/.match("hello world,world hello!") a是一个matchdata对象puts a[0] =>ll0如果能够匹配,=~返回匹配的字符串位 阅读全文
posted @ 2013-07-25 23:27 dami.van 阅读(525) 评论(0) 推荐(0)
摘要:引用连接:为处理与正则表达式的匹配过程相关的信息而设置的类. 可以通过下列途径Regexp.last_matchRegexp#match, String#match$~得到该类的实例.超类:Object方法:self[n]返回第n个子字符串. 0表示整个匹配部分. 若n为负值,则从尾部算起(末尾的元素是第-1个). 若不存在第n个元素则返回nil./(foo)(bar)(BAZ)?/ =~ "foobarbaz"p $~.to_a # => ["foobar", "foo", "bar", nil]p $~[ 阅读全文
posted @ 2013-07-25 23:12 dami.van 阅读(1790) 评论(0) 推荐(0)
摘要:1.str="abc123"puts str[0].chr => aputs str[0] =>a的ascii码2.中文字符串的正则表达式文本编码:utf-8文件第一行:#encoding:urf-8require "iconv" str="八万"reg=/(.+)万/data=reg.match(str)result = Iconv.iconv("GBK","UTF-8",data[0]) puts result =>输出:八万3.含中文字符串的长度文本编码:utf-8文件第 阅读全文
posted @ 2013-07-25 14:58 dami.van 阅读(235) 评论(0) 推荐(0)
摘要:Apatana Studio只会找ruby/bin的ruby执行档....为了在Apatana Studio用JRuby,除了设定好Path之外还要在JRuby/bin下建立一的ruby.bat,里面填写@c:\jruby-1.7.0\bin\jruby %*后储存,这样就可以用JRuby了JRuby的安装路径而不一定是jruby-1.7.0 阅读全文
posted @ 2013-07-25 13:29 dami.van 阅读(182) 评论(0) 推荐(0)