如何在mocha框架中更正此测试用例?(How to correct this test case in mocha framework?)
我正在尝试为节点应用程序编写测试用例,它使用mocha作为测试框架。
test.js
var register = require('../routes/users'); var request = require('request'); var baseUrl = 'http://localhost:5000'; describe('registerUser()', function() { it('check email is already registered', function (done) { request.post({uri:baseUrl+'/register', form :{ username: 'test', email: 'test@test.com' }}, function (e, res, body) { res.should.have.property('statusCode', 201); res.should.have.property('regErr', 'This email is already taken!'); }) }); })
regErr
作为render函数registerUser
参数给出。 我期望参数regErr
将被设置为响应的属性并且可以进入测试。 请检查我在github中的registerUser函数 。 我正在尝试为此功能创建一个测试用例。上面的代码在测试用例中获取的响应中没有名为
regErr
属性。如何更正渲染参数也可以作为响应属性?
我需要更改实际的函数
registerUser
才能得到这个吗? 如果是这样,我怎样才能实现这一目标?I am trying to write test case for node application, which is using mocha as test framework.
test.js
var register = require('../routes/users'); var request = require('request'); var baseUrl = 'http://localhost:5000'; describe('registerUser()', function() { it('check email is already registered', function (done) { request.post({uri:baseUrl+'/register', form :{ username: 'test', email: 'test@test.com' }}, function (e, res, body) { res.should.have.property('statusCode', 201); res.should.have.property('regErr', 'This email is already taken!'); }) }); })
The
regErr
is given as parameter in functionregisterUser
on render. I expected the parameterregErr
will be set as property of response and can be get in test. Please check my registerUser function in github. I am trying create a test case for this function.Above code doesn't have property called
regErr
in response fetched in test case.How to correct so that the rendering parameters can also be property in response?
Shall I need to change the actual function
registerUser
to get this? If so, how can I achieve this?
原文:https://stackoverflow.com/questions/15811297
最满意答案
这是一个常见的问题。 你几乎肯定会遇到权限问题。 要解决它,请确保
apache
用户具有对整个存储库的读/写访问权限。 要做到这一点,请在您的svn存储库下面的所有内容中选择chown -R apache:apache *
,chmod -R 664 *
。另外,如果你仍然停留在这里和这里 。
更新在评论中回答OP的其他问题:
“664”字符串是权限的八进制(基数8)表示形式。 这里有三位数字,分别代表该文件或目录的所有者 , 组和其他人 (有时称为“world”)的权限。
请注意,每个8位数字可以用3位表示(“0”表示“0”表示“7”表示)。 每一点都意味着什么:
- 第一位:读权限
- 第二位:写权限
- 第三位:执行权限
例如,764文件将意味着:
- 所有者(第一位)具有读/写/执行(7)权限
- 该组(第二位)具有读/写(6)权限
- 所有其他人(第三位数)都有阅读(4)权限
希望清除事情!
This is a common problem. You're almost certainly running into permissions issues. To solve it, make sure that the
apache
user has read/write access to your entire repository. To do that,chown -R apache:apache *
,chmod -R 664 *
for everything under your svn repository.Also, see here and here if you're still stuck.
Update to answer OP's additional question in comments:
The "664" string is an octal (base 8) representation of the permissions. There are three digits here, representing permissions for the owner, group, and everyone else (sometimes called "world"), respectively, for that file or directory.
Notice that each base 8 digit can be represented with 3 bits (000 for '0' through 111 for '7'). Each bit means something:
- first bit: read permissions
- second bit: write permissions
- third bit: execute permissions
For example, 764 on a file would mean that:
- the owner (first digit) has read/write/execute (7) permission
- the group (second digit) has read/write (6) permission
- everyone else (third digit) has read (4) permission
Hope that clears things up!
相关问答
更多-
这是一个常见的问题。 你几乎肯定会遇到权限问题。 要解决它,请确保apache用户具有对整个存储库的读/写访问权限。 要做到这一点,请在您的svn存储库下面的所有内容中选择chown -R apache:apache * , chmod -R 664 * 。 另外,如果你仍然停留在这里和这里 。 更新在评论中回答OP的其他问题: “664”字符串是权限的八进制(基数8)表示形式。 这里有三位数字,分别代表该文件或目录的所有者 , 组和其他人 (有时称为“world”)的权限。 请注意,每个8位数字可以用3位 ...
-
我在Ubuntu ec2实例上有同样的问题。 我在第7页关注这个亚马逊的文章: http://d36cz9buwru1tt.cloudfront.net/AWS_NoSQL_MongoDB.pdf /etc/mongodb.conf中的Mongodb路径设置为/var/lib/mongodb (主安装位置和工作)。 当我更改为/data/db (EBS卷)时,我得到“errno:13 Permission denied”。 首先我运行sudo service mongodb stop 。 然后我使用ls - ...
-
Subversion提交失败(Subversion commit fails)[2022-07-26]
将存储库的所有者更改为您的用户: $ sudo chown -R [username] /var/svn/repos/repository 如果您是使用存储库的唯一人员,这应该足够了,并且只能在本地使用。 如果您需要更多本地用户的权限,请考虑创建一个单独的组并授予此组写入存储库的权限。 最后,如果您想允许远程访问存储库,我建议根本不使用本地文件协议(甚至是本地)。 Change the owner of the repository to your user: $ sudo chown -R [usern ... -
挂断后SVN提交失败(SVN commits fail after hang-up)[2023-09-08]
事实证明,SVN错误的原因是硬盘故障。 糟糕的群集等等。 As it turned out, the cause of SVN errors was the hard disk failure. Bad clusters and so on. -
db\txn-current是服务器上存储库数据中的文件,如果使用文本编辑器打开它,则该文件应包含当前版本号。 如果不是这种情况(因为错误消息似乎表明),那么您应该首先尝试在服务器上运行svnadmin recover D:\SVNROOT\UC\ 。 您还应该运行svnadmin verify D:\SVNROOT\UC\以检查存储库是否存在任何其他问题。 db\txn-current is a file in the repository data on the server which should ...
-
svn问题(只读锁)(svn problem (read-only lock))[2023-03-15]
是的,可能是它的权限。 确保运行svn服务器的用户具有写入存储库和所有文件/子目录的权限。 请记住,如果您通过Apache使用svn,那么用户将是www 。 Yes, likely it's permissions. Make sure the user the svn server is run under has permission to write to the repository and all files/subdirectories. Remember that if you're usin ... -
分支项目时“无法打开锁定文件:权限被拒绝”(“could not open lock file: Permission denied” when branching a project)[2022-04-06]
问题是确实没有为该文件授予文件系统的写权限。 因此错误消息Permission denied 。 The problem was that indeed the write permission on the file system was not granted for this file. Hence the error message Permission denied. -
svn安装权限问题(svn setup permission issues)[2022-04-05]
确保您的用户拥有任何文件夹的执行权限。 770应该为你工作(如牛顿福尔斯指出),因为这将允许小组执行。 Make sure your user has execute permission on any folder. 770 should work for you (as Newton Falls pointed out) as this will allow group execute. -
在与权限斗争之后,我决定再看看“howto”并解决了这个问题。 我基本上忘了输入: chcon -R -t httpd_sys_content_t /var/www/svn/repo chcon -R -t httpd_sys_rw_content_t /var/www/svn/repo 希望它可以帮助别人。 After fighting with permissions, I decided to just look again at the "howto" and solved the issue. ...
-
Subversion正在使用正确的路径。 错误来自服务器,而不是来自客户端。 路径/home/foo/webapps/com_foo_svn/db/txn-current-lock位于服务器端。 因此,您应该检查服务器上的权限 。 Subversion is using the correct path. The error comes from the server, not from the client. The path /home/foo/webapps/com_foo_svn/db/txn-cu ...