我正在尝试对具有需要请求对象的方法的服务进行单元测试.
import org.springframework.web.context.request.RequestContextHolder as RCH
class AddressService {
def update (account, params) {
try {
def request = RCH.requestAttributes.request
// retrieve some info from the request object such as the IP ...
// Implement update logic
} catch (all) {
/* do something with the exception */
}
}
}
Run Code Online (Sandbox Code Playgroud)
你如何模拟请求对象?
顺便说一句,我正在使用Spock对我的课进行单元测试.
谢谢
我是gruntjs的新手,这是我简单的gruntfile:
/* global module:false */
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
watch: {
tasks: 'coffee'
},
coffee: {
compile: {
files: {
'js/javascript/*.js': ['js/coffeescript/*.coffee'] // 1:1 compile
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-coffee');
// Default task.
grunt.registerTask('default', 'coffee');
};
Run Code Online (Sandbox Code Playgroud)
当我运行咕噜声时它编译得很好.但是,当我运行grunt watch时,它只是在等待而不是检测我的更改.
我正在编写功能测试并处理淡入淡出的模态窗口.
显示和现在有什么区别?
例如,我有:
settingsModule.container.displayed and settingsModule.container.present
Run Code Online (Sandbox Code Playgroud)
其中settingsModule代表我的模态窗口.
在测试我的模态窗口(来自Twitter的bootstrap的模态)时,我通常这样做:
def "should do ... "() {
setup:
topMenu.openSettingsModal()
expect:
settingsModule.timeZone.value() == "Asia/Hong_Kong"
cleanup:
settingsModule.closeSettingsModal()
}
def "should save the time zone"() {
setup:
topMenu.openSettingsModal()
settingsModule.timeZone = "Japan"
when:
settingsModule.saveSettings()
then:
settingsModule.alertSuccess.size() == 1
settingsModule.alertSuccess.text() == "Settings updated"
when:
settingsModule.saveSettings()
then:
settingsModule.alertSuccess.size() == 1
cleanup:
settingsModule.closeSettingsModal()
}
Run Code Online (Sandbox Code Playgroud)
等等.在我的模块中,我有:
void openSettingsModal() {
username.click()
settingsLink.click()
}
void closeSettingsModal() {
form.cancel().click()
}
Run Code Online (Sandbox Code Playgroud)
我总是抱怨:"必须显示元素才能点击".
在我的openSettingsModal和closeSettingsModal中,我尝试了许多waitFor与时间间隔的组合并使用present或not ...无法弄明白.
任何指针都将受到高度赞赏.谢谢!
我目前正在使用guard来观察我的.coffee和.scss文件的更改并进行适当的编译.
现在,gruntjs和yeoman提供类似的功能.
谢谢!
我开始使用Grails,我观看了很多视频,主持人用命令行和文本编辑器(如textmate)演示了Grails 2.X.
这是我的两个问题:
它是推荐的工作流程还是最流行的工作流程?或者大多数人使用STS?
我喜欢文本编辑器,我想知道是否可以使用Sublime Text 2调试Grails应用程序
谢谢
grails ×3
groovy ×2
gruntjs ×2
spock ×2
coffeescript ×1
debugging ×1
geb ×1
guard ×1
javascript ×1
node.js ×1
ruby ×1
sublimetext ×1
unit-testing ×1
yeoman ×1