Peterfei

上主是我的牧者,我实在一无所缺


  • 首页

  • 归档

  • 标签

rails minitest自动化测试

发表于 2015-11-12   |   分类于 Ruby   |  

##Gemfile加入相关测试驱动:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#测试组
group :test do
gem "minitest"
gem 'minitest-spec-rails'
gem 'minitest-reporters'
gem 'spring'
gem 'guard'
gem 'guard-minitest'
# 添加调用跟踪静默程序
# gem 'mini_backtrace'
gem 'ruby-prof'
gem 'minitest-rails-capybara'
gem 'autotest-standalone' # The file '.autotest' makes sure the tests are run via test server (spork).
gem 'autotest-rails-pure' # -pure gives us autotest without ZenTest gem.
gem 'autotest-growl' # growl notifications, complains a little bit if growl isn't installed
gem 'autotest-fsevent' # react to filesystem events, save your CPU
gem 'spork-minitest'
end

##初始化guard:

guard init minitest

##配置guard:

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
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
guard :minitest, spring: true, all_on_start: false do
# with Minitest::Unit
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r{^test/test_helper\.rb$}) { 'test' }
# with Minitest::Spec
# watch(%r{^spec/(.*)_spec\.rb$})
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
# watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
# Rails 4
watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
watch(%r{^test/.+_test\.rb$})
watch(%r{^test/test_helper\.rb$}) { 'test' }
# Rails < 4
# watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
# watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
# watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
end

##运行Guard:

输入 guard 命令运行测试

##例外

如果database不用默认的数据库迁移,测试时可以在db下放入structure.sql, 该配置为数据库结构,然后更改配置文件 application.rb:

1
config.active_record.schema_format = :sql

运行:rake db:test:prepare

##生成集成化测试文件

rails g test_unit:integration testName

##生成model测试文件
rails g test_unit:model

Ionic 更新默认图标

发表于 2015-11-04   |   分类于 Ionic   |  

项目中要替换ionic 默认的icon 图标,Google 一下,大多是让图标生成svg的格式,下面有一种比较容易的方式去实现:

e.g. 在浏览器的调试模式,选中需要替换的图标,找到如下代码:

1
2
3
.ion-ios-home-outline:before {
content: "\f447";
}

在/img/找出要替换的icon图,如car.png
在样式表里写入如下代码:

1
2
3
4
.ion-ios-home-outline:before {
/*content: "\f447";*/
content: url('../img/car.png') !important;
}

效果图

puma 在nginx 启动后报错解决

发表于 2015-10-31   |   分类于 ROR   |  

##在Centos上部署时遇到如下错误:

puma nginx connect() Permission denied

解决方法:在nginx.conf 配置文件中加入了puma 用户:
user deploy

puma 启动时的用户,如此启动正常。

Sublime 中自定义snippets

发表于 2015-10-29   |   分类于 工具   |  

##选择tool->new snippet
内容如下:

1
2
3
4
5
6
7
8
9
<snippet>
<content><![CDATA[
Hello, ${1:this} is a ${2:snippet}.
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>

  1. Hello, ${1:this} is a ${2:snippet} 这正是你要插入到文档中的文本。在此节放入的任何片段都会被插入到你的文档中。
  2. tabTrigger 此节是可选的配置,默认是被注释掉的。默认 hello 的意思是:如果你在某个文档里输入了单词 hello ,然后按下 Tab 键,接着 hello 就会被替换为1中定义的代码片段。再次按下Tab键,接着snippet会被替换为2中定义的代码片段
  3. scope 此节也是可选配置,默认是被注释掉的。默认 source.php 的意思是:只有在编辑 php 源码的时候,才能用此代码片段

##保存代码片段文件
在能自定义代码片段之前,应该首先保存。在保存文件对话框里,需要明确的指定文件的扩展名为.sublime-snippet,然后把文件保存到默认目录(当前用户主目录下的\Sublime Text 3\Packages\User目录中)。

保存文件之后,就可以测试上面提到的tabTrigger功能了。如果不再使用此功能,可以在此注释掉.

##修改代码片段文件
在创建新代码片段中提到过 Hello, ${1:this} is a ${2:snippet} ,其中 ${1:this} 和 ${2:snippet} 是占位符。在插入代码片段后,单词 this 被选中,如果键入内容,this 将会被替换掉,接着按下 Tab 键,将会选中单词 snippet,如果键入内容,snippet 将会被替换掉。

##绑定快捷键

可以将上述的操作绑定到一个快捷键,在不键入任何文本的情况下,直接按快捷键插入代码片段。

点击菜单栏的 Preferences 的子菜单 Key Binding – User,在打开的文件的方括号内部粘贴如下配置:

1
{ “keys”: [“ctrl+1″], “command”: “insert_snippet”, “args”: {“name”: “Packages/User/example.sublime-snippet”} }

现在简单介绍一下这段配置:

  1. “keys”: [“ctrl+1″] 这个定义了触发此命令的快捷键。

  2. “command”: “insert_snippet” 这个是需要触发的命令的名字。

  3. “args”: {“name”: “Packages/User/example.sublime-snippet”} 这个是需要传入到上述命令的参数。这里把代码片段文件的相对路径传递过去。

保存配置文件,现在就可以用快捷键插入代码片段了。

以下是我Ruby的注释代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<snippet>
<content><![CDATA[
# ########################################################
# | Software: ${1}
# | Version: 2015.10
# | Site: http://peterfei.me
# |--------------------------------------------------------
# | Author: peterfei <peterfeispace@gmail.com>
# | Copyright (c) 2012-2015, http://peterfei.me. All Rights
#Reserved.
# | Time: ${2}
# ########################################################
${3}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>

因为上例中有写Time 获取当前时间的,于是写个获取当前时间的:

创建插件:Tools → New Plugin:

1
2
3
4
5
6
7
8
9
import datetime
import sublime_plugin
class AddCurrentTimeCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command("insert_snippet",
{
"contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
)

保存为Sublime Text 2\Packages\User\addCurrentTime.py

创建快捷键:Preference → Key Bindings - User:

1
2
3
4
5
6
7
8
[
{
"command": "add_current_time",
"keys": [
"ctrl+shift+."
]
}
]

此时使用快捷键ctrl+shift+.即可在当前光标处插入当前时间,如下:

1
2
3
4
5
6
7
8
9
10
# ########################################################
# | Software: test
# | Version: 2015.10
# | Site: http://peterfei.me
# |--------------------------------------------------------
# | Author: peterfei <peterfeispace@gmail.com>
# | Copyright (c) 2012-2015, http://peterfei.me. All Rights
#Reserved.
# | Time: 2015-10-29 09:58:53
# ########################################################

angularjs mobiscroll 日期用例

发表于 2015-10-27   |   分类于 前端   |  

Angularjs 写了个mobiscroll directive :

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
.directive('mobiDateTimePicker', function() {
return {
restrict: 'A',
link: function($scope, element, attrs) {
return $(element).mobiscroll().datetime({
theme: 'default',
display: 'bottom',
lang:'zh',
minWidth:40,
steps:{ minute: 15},
rows:3,
// dayText: '日', monthText: '月', yearText: '年',
dateFormat: 'yy-MM-dd',
timeFormat: 'HH:ii:ss',
// timeWheels: 'HHii',
showNow: true,
showLabel:true,
dateOrder: 'yyyyMMddDD',
// tap:true,
// invalid:[{'10/27',start:'18:00',end:"19:00"}]
headerText: function (valueText) { //自定义弹出框头部格式
return valueText;
},
// dayNames:['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
});
}
};
})

其中:minWidth:40是控件的显示高度,dateOrder: 'yyyyMMddDD',可显示友好的星期+日期:

1…101112…16
peterfei

peterfei

peterfei|技术|上主是我的牧者

80 日志
14 分类
62 标签
RSS
github
© 2025 peterfei
由 Hexo 强力驱动
主题 - NexT.Mist