gpt4 book ai didi

css - 如何在 rspec (Rails 4/rspec3) 上测试文件大小

转载 作者:太空宇宙 更新时间:2023-11-04 12:27:28 24 4
gpt4 key购买 nike

我想测试我的 css 文件和 javascript 文件(本地)是否低于 500kb(我想确保在我们开发的任何时候,这些严重影响我们前端的文件保持在某个值以下)。

我正在使用以下代码,但出现错误

/spec/controllers/application_controller_spec.rb

describe 'Sizes of files that significantly impact app frontend are under a certain size' do
it "should have css files under 500ko " do
expect( File.size("app/assets/stylesheets/custom.css.scss") ).to be <= 500
end

it "should have javascript filec" do
expect( File.size("app/assets/stylesheets/custom.css.scss") ).to be <= 500
end
end

但我收到错误:

ApplicationController Sizes of files that significantly impact app frontend are under a certain size should have css files under 500ko 
Failure/Error: expect( File.size("app/assets/stylesheets/custom.css.scss") ).to be <= 500
expected: <= 500
got: 15296
# ./spec/controllers/application_controller_spec.rb:90:in `block (3 levels) in <top (required)>'
# /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/zeus-0.15.3/lib/zeus/rails.rb:212:in `test'
# /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/zeus-0.15.3/lib/zeus.rb:148:in `block in command'
# /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/zeus-0.15.3/lib/zeus.rb:135:in `fork'
# /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/zeus-0.15.3/lib/zeus.rb:135:in `command'
# /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/zeus-0.15.3/lib/zeus.rb:50:in `go'
# -e:1:in `<main>'

我怎么会得到这个号码?我应该做某种乘法来将 kb 转换为位或其他东西吗?

编辑

事实上,我需要以字节为单位转换 500Kb。

最佳答案

对于运算符比较,您需要使用 be:

expect(35).to be >= 20

检查 the documentation更多示例。

关于css - 如何在 rspec (Rails 4/rspec3) 上测试文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27911221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com